2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-03-30 13:31:41 +00:00
|
|
|
* Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
|
|
|
|
* Copyright (C) 1997 Josh MacDonald
|
|
|
|
*
|
2004-09-22 15:12:24 +00:00
|
|
|
* file-open.c
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-03-30 13:31:41 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-03-30 13:31:41 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-03-30 13:31:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
|
|
|
#include <gegl.h>
|
2001-08-17 14:27:31 +00:00
|
|
|
|
2008-11-10 08:21:36 +00:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2007-08-07 09:26:28 +00:00
|
|
|
|
2001-05-09 22:34:59 +00:00
|
|
|
#include "core/core-types.h"
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2012-04-22 17:07:35 +02:00
|
|
|
#include "gegl/gimp-babl.h"
|
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
#include "core/gimp.h"
|
2004-04-14 23:37:34 +00:00
|
|
|
#include "core/gimpcontext.h"
|
2004-06-28 21:42:19 +00:00
|
|
|
#include "core/gimpdocumentlist.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
#include "core/gimpimage.h"
|
2004-06-28 21:42:19 +00:00
|
|
|
#include "core/gimpimage-merge.h"
|
2004-03-14 19:10:55 +00:00
|
|
|
#include "core/gimpimage-undo.h"
|
2002-04-19 12:05:47 +00:00
|
|
|
#include "core/gimpimagefile.h"
|
2004-06-28 21:42:19 +00:00
|
|
|
#include "core/gimplayer.h"
|
2006-03-29 23:56:07 +00:00
|
|
|
#include "core/gimpparamspecs.h"
|
2004-08-10 18:47:21 +00:00
|
|
|
#include "core/gimpprogress.h"
|
2001-05-09 02:32:03 +00:00
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
#include "pdb/gimppdb.h"
|
2001-12-01 00:14:14 +00:00
|
|
|
|
2016-01-03 20:05:27 +01:00
|
|
|
#include "plug-in/gimppluginmanager-file.h"
|
2006-08-05 21:21:01 +00:00
|
|
|
#include "plug-in/gimppluginprocedure.h"
|
2006-10-27 13:52:40 +00:00
|
|
|
|
2017-02-17 20:59:17 +01:00
|
|
|
#include "file-import.h"
|
2001-03-30 13:31:41 +00:00
|
|
|
#include "file-open.h"
|
2014-07-11 01:52:17 +02:00
|
|
|
#include "file-remote.h"
|
2009-05-01 09:03:13 +02:00
|
|
|
#include "gimp-file.h"
|
2001-10-25 13:30:01 +00:00
|
|
|
|
2003-03-25 16:38:19 +00:00
|
|
|
#include "gimp-intl.h"
|
2001-03-30 13:31:41 +00:00
|
|
|
|
|
|
|
|
2016-01-03 20:05:27 +01:00
|
|
|
static void file_open_sanitize_image (GimpImage *image,
|
|
|
|
gboolean as_new);
|
|
|
|
static void file_open_convert_items (GimpImage *dest_image,
|
|
|
|
const gchar *basename,
|
|
|
|
GList *items);
|
2016-05-19 23:51:44 +02:00
|
|
|
static GList * file_open_get_layers (GimpImage *image,
|
2016-01-03 20:05:27 +01:00
|
|
|
gboolean merge_visible,
|
|
|
|
gint *n_visible);
|
|
|
|
static gboolean file_open_file_proc_is_import (GimpPlugInProcedure *file_proc);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
|
2001-03-30 13:31:41 +00:00
|
|
|
/* public functions */
|
|
|
|
|
2001-04-28 15:11:29 +00:00
|
|
|
GimpImage *
|
2006-04-05 08:38:33 +00:00
|
|
|
file_open_image (Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file,
|
|
|
|
GFile *entered_file,
|
2007-04-17 15:54:01 +00:00
|
|
|
gboolean as_new,
|
2006-04-12 12:49:29 +00:00
|
|
|
GimpPlugInProcedure *file_proc,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpPDBStatusType *status,
|
2006-04-05 08:38:33 +00:00
|
|
|
const gchar **mime_type,
|
|
|
|
GError **error)
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2012-05-04 00:50:23 +02:00
|
|
|
GimpValueArray *return_vals;
|
2014-07-07 00:46:25 +02:00
|
|
|
GimpImage *image = NULL;
|
2014-07-11 01:52:17 +02:00
|
|
|
GFile *local_file = NULL;
|
2014-07-07 00:46:25 +02:00
|
|
|
gchar *path = NULL;
|
|
|
|
gchar *entered_uri = NULL;
|
2014-07-22 20:29:52 +02:00
|
|
|
GError *my_error = NULL;
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2001-10-29 11:47:11 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-08-10 18:47:21 +00:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2014-07-07 00:46:25 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (entered_file), NULL);
|
2001-10-29 11:47:11 +00:00
|
|
|
g_return_val_if_fail (status != NULL, NULL);
|
2003-03-05 11:25:59 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2001-10-29 11:47:11 +00:00
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
*status = GIMP_PDB_EXECUTION_ERROR;
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2014-07-08 20:23:34 +02:00
|
|
|
/* FIXME enable these tests for remote files again, needs testing */
|
|
|
|
if (g_file_is_native (file) &&
|
|
|
|
g_file_query_exists (file, NULL))
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2014-07-07 00:46:25 +02:00
|
|
|
GFileInfo *info;
|
2002-04-14 14:38:55 +00:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
info = g_file_query_info (file,
|
|
|
|
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
|
|
|
|
G_FILE_QUERY_INFO_NONE,
|
|
|
|
NULL, error);
|
|
|
|
if (! info)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (g_file_info_get_file_type (info) != G_FILE_TYPE_REGULAR)
|
|
|
|
{
|
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("Not a regular file"));
|
2014-10-07 15:23:19 +02:00
|
|
|
g_object_unref (info);
|
2014-07-07 00:46:25 +02:00
|
|
|
return NULL;
|
2002-04-14 14:38:55 +00:00
|
|
|
}
|
2012-11-17 21:21:32 +01:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
if (! g_file_info_get_attribute_boolean (info,
|
|
|
|
G_FILE_ATTRIBUTE_ACCESS_CAN_READ))
|
2012-11-17 21:21:32 +01:00
|
|
|
{
|
2014-07-07 00:46:25 +02:00
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
2015-05-02 23:43:06 +03:00
|
|
|
_("Permission denied"));
|
2014-10-07 15:23:19 +02:00
|
|
|
g_object_unref (info);
|
2014-07-08 20:23:34 +02:00
|
|
|
return NULL;
|
2012-11-17 21:21:32 +01:00
|
|
|
}
|
2014-10-07 15:23:19 +02:00
|
|
|
|
|
|
|
g_object_unref (info);
|
2001-03-30 13:31:41 +00:00
|
|
|
}
|
2014-07-07 00:46:25 +02:00
|
|
|
|
2015-04-29 18:57:39 -04:00
|
|
|
if (! file_proc)
|
2016-01-03 20:05:27 +01:00
|
|
|
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
|
|
|
|
GIMP_FILE_PROCEDURE_GROUP_OPEN,
|
|
|
|
file, error);
|
2015-04-29 18:57:39 -04:00
|
|
|
|
|
|
|
if (! file_proc)
|
2016-11-07 18:28:39 +01:00
|
|
|
{
|
|
|
|
/* don't bail out on remote files, they might need to be
|
|
|
|
* downloaded for magic matching
|
|
|
|
*/
|
|
|
|
if (g_file_is_native (file))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_clear_error (error);
|
|
|
|
}
|
2015-04-29 18:57:39 -04:00
|
|
|
|
2014-07-22 20:29:52 +02:00
|
|
|
if (! g_file_is_native (file) &&
|
|
|
|
! file_remote_mount_file (gimp, file, progress, &my_error))
|
|
|
|
{
|
|
|
|
if (my_error)
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
else
|
|
|
|
*status = GIMP_PDB_CANCEL;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-07 18:28:39 +01:00
|
|
|
if (! file_proc || ! file_proc->handles_uri)
|
2014-07-11 01:52:17 +02:00
|
|
|
{
|
|
|
|
path = g_file_get_path (file);
|
|
|
|
|
2014-07-22 00:08:59 +02:00
|
|
|
if (! path)
|
2014-07-11 01:52:17 +02:00
|
|
|
{
|
2014-07-22 20:29:52 +02:00
|
|
|
local_file = file_remote_download_image (gimp, file, progress,
|
|
|
|
&my_error);
|
2014-07-11 01:52:17 +02:00
|
|
|
|
|
|
|
if (! local_file)
|
|
|
|
{
|
|
|
|
if (my_error)
|
|
|
|
g_propagate_error (error, my_error);
|
|
|
|
else
|
|
|
|
*status = GIMP_PDB_CANCEL;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-11-07 18:28:39 +01:00
|
|
|
/* if we don't have a file proc yet, try again on the local
|
|
|
|
* file
|
|
|
|
*/
|
|
|
|
if (! file_proc)
|
|
|
|
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
|
|
|
|
GIMP_FILE_PROCEDURE_GROUP_OPEN,
|
|
|
|
local_file, error);
|
|
|
|
|
|
|
|
if (! file_proc)
|
|
|
|
{
|
|
|
|
g_file_delete (local_file, NULL, NULL);
|
|
|
|
g_object_unref (local_file);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-07-11 01:52:17 +02:00
|
|
|
path = g_file_get_path (local_file);
|
|
|
|
}
|
|
|
|
}
|
2014-07-07 00:46:25 +02:00
|
|
|
|
|
|
|
if (! path)
|
|
|
|
path = g_file_get_uri (file);
|
|
|
|
|
|
|
|
entered_uri = g_file_get_uri (entered_file);
|
|
|
|
|
|
|
|
if (! entered_uri)
|
|
|
|
entered_uri = g_strdup (path);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2016-07-03 18:26:37 +02:00
|
|
|
if (progress)
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (progress), (gpointer) &progress);
|
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
return_vals =
|
|
|
|
gimp_pdb_execute_procedure_by_name (gimp->pdb,
|
2007-12-02 18:05:54 +00:00
|
|
|
context, progress, error,
|
2009-08-29 12:40:40 +02:00
|
|
|
gimp_object_get_name (file_proc),
|
2006-04-26 09:13:47 +00:00
|
|
|
GIMP_TYPE_INT32, run_mode,
|
2014-07-07 00:46:25 +02:00
|
|
|
G_TYPE_STRING, path,
|
|
|
|
G_TYPE_STRING, entered_uri,
|
2006-04-26 09:13:47 +00:00
|
|
|
G_TYPE_NONE);
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2016-07-03 18:26:37 +02:00
|
|
|
if (progress)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (progress), (gpointer) &progress);
|
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
g_free (path);
|
|
|
|
g_free (entered_uri);
|
2002-04-14 14:38:55 +00:00
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
*status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
|
2001-03-30 13:31:41 +00:00
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
if (*status == GIMP_PDB_SUCCESS)
|
2014-07-11 01:52:17 +02:00
|
|
|
image = gimp_value_get_image (gimp_value_array_index (return_vals, 1),
|
|
|
|
gimp);
|
|
|
|
|
|
|
|
if (local_file)
|
2001-03-30 13:31:41 +00:00
|
|
|
{
|
2014-07-11 01:52:17 +02:00
|
|
|
if (image)
|
|
|
|
gimp_image_set_file (image, file);
|
|
|
|
|
2014-07-22 20:29:52 +02:00
|
|
|
g_file_delete (local_file, NULL, NULL);
|
2014-07-11 01:52:17 +02:00
|
|
|
g_object_unref (local_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
2006-03-29 23:56:07 +00:00
|
|
|
if (image)
|
2002-04-19 14:09:53 +00:00
|
|
|
{
|
2007-09-20 21:23:05 +00:00
|
|
|
/* Only set the load procedure if it hasn't already been set. */
|
|
|
|
if (! gimp_image_get_load_proc (image))
|
|
|
|
gimp_image_set_load_proc (image, file_proc);
|
|
|
|
|
|
|
|
file_proc = gimp_image_get_load_proc (image);
|
|
|
|
|
2004-05-14 00:01:11 +00:00
|
|
|
if (mime_type)
|
2017-05-04 23:22:37 +02:00
|
|
|
*mime_type = g_slist_nth_data (file_proc->mime_types_list, 0);
|
2002-04-19 14:09:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-02 18:05:54 +00:00
|
|
|
if (error && ! *error)
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("%s plug-in returned SUCCESS but did not "
|
|
|
|
"return an image"),
|
2016-01-01 20:52:45 +01:00
|
|
|
gimp_procedure_get_label (GIMP_PROCEDURE (file_proc)));
|
2007-12-02 18:05:54 +00:00
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
*status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*status != GIMP_PDB_CANCEL)
|
|
|
|
{
|
2007-12-02 18:05:54 +00:00
|
|
|
if (error && ! *error)
|
|
|
|
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("%s plug-In could not open image"),
|
2016-01-01 20:52:45 +01:00
|
|
|
gimp_procedure_get_label (GIMP_PROCEDURE (file_proc)));
|
2001-03-30 13:31:41 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
gimp_value_array_unref (return_vals);
|
2006-03-30 13:00:17 +00:00
|
|
|
|
2006-10-27 13:52:40 +00:00
|
|
|
if (image)
|
2007-08-11 18:27:01 +00:00
|
|
|
{
|
2015-09-09 21:21:20 +02:00
|
|
|
gimp_image_undo_disable (image);
|
|
|
|
|
2009-05-24 17:54:25 +02:00
|
|
|
if (file_open_file_proc_is_import (file_proc))
|
|
|
|
{
|
2017-02-17 20:59:17 +01:00
|
|
|
file_import_image (image, context, file,
|
|
|
|
run_mode == GIMP_RUN_INTERACTIVE,
|
|
|
|
progress);
|
2009-05-24 17:54:25 +02:00
|
|
|
}
|
2015-09-09 21:21:20 +02:00
|
|
|
|
|
|
|
/* Enables undo again */
|
|
|
|
file_open_sanitize_image (image, as_new);
|
2009-04-23 20:44:12 +02:00
|
|
|
}
|
|
|
|
|
2006-03-30 13:00:17 +00:00
|
|
|
return image;
|
2001-03-30 13:31:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 08:21:36 +00:00
|
|
|
/**
|
|
|
|
* file_open_thumbnail:
|
|
|
|
* @gimp:
|
|
|
|
* @context:
|
|
|
|
* @progress:
|
2014-07-07 00:46:25 +02:00
|
|
|
* @file: an image file
|
2008-11-10 08:21:36 +00:00
|
|
|
* @size: requested size of the thumbnail
|
|
|
|
* @mime_type: return location for image MIME type
|
|
|
|
* @image_width: return location for image width
|
|
|
|
* @image_height: return location for image height
|
2012-04-11 21:54:23 +02:00
|
|
|
* @format: return location for image format (set to NULL if unknown)
|
2008-11-10 08:21:36 +00:00
|
|
|
* @num_layers: return location for number of layers
|
|
|
|
* (set to -1 if the number of layers is not known)
|
|
|
|
* @error:
|
|
|
|
*
|
|
|
|
* Attempts to load a thumbnail by using a registered thumbnail loader.
|
|
|
|
*
|
|
|
|
* Return value: the thumbnail image
|
|
|
|
*/
|
2004-11-13 17:06:06 +00:00
|
|
|
GimpImage *
|
2008-11-10 08:21:36 +00:00
|
|
|
file_open_thumbnail (Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file,
|
2008-11-10 08:21:36 +00:00
|
|
|
gint size,
|
|
|
|
const gchar **mime_type,
|
|
|
|
gint *image_width,
|
|
|
|
gint *image_height,
|
2012-04-11 21:54:23 +02:00
|
|
|
const Babl **format,
|
2008-11-10 08:21:36 +00:00
|
|
|
gint *num_layers,
|
|
|
|
GError **error)
|
2004-11-13 17:06:06 +00:00
|
|
|
{
|
2006-04-05 08:38:33 +00:00
|
|
|
GimpPlugInProcedure *file_proc;
|
|
|
|
GimpProcedure *procedure;
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2014-07-07 00:46:25 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2004-11-13 17:06:06 +00:00
|
|
|
g_return_val_if_fail (mime_type != NULL, NULL);
|
|
|
|
g_return_val_if_fail (image_width != NULL, NULL);
|
|
|
|
g_return_val_if_fail (image_height != NULL, NULL);
|
2012-04-11 21:54:23 +02:00
|
|
|
g_return_val_if_fail (format != NULL, NULL);
|
2008-11-10 08:21:36 +00:00
|
|
|
g_return_val_if_fail (num_layers != NULL, NULL);
|
2007-12-02 18:05:54 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
*image_width = 0;
|
|
|
|
*image_height = 0;
|
2012-04-11 21:54:23 +02:00
|
|
|
*format = NULL;
|
2008-11-10 08:21:36 +00:00
|
|
|
*num_layers = -1;
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2016-01-03 20:05:27 +01:00
|
|
|
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
|
|
|
|
GIMP_FILE_PROCEDURE_GROUP_OPEN,
|
|
|
|
file, NULL);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
if (! file_proc || ! file_proc->thumb_loader)
|
|
|
|
return NULL;
|
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
procedure = gimp_pdb_lookup_procedure (gimp->pdb, file_proc->thumb_loader);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2006-03-31 17:42:13 +00:00
|
|
|
if (procedure && procedure->num_args >= 2 && procedure->num_values >= 1)
|
2004-11-13 17:06:06 +00:00
|
|
|
{
|
|
|
|
GimpPDBStatusType status;
|
2012-05-04 00:50:23 +02:00
|
|
|
GimpValueArray *return_vals;
|
2006-03-30 13:00:17 +00:00
|
|
|
GimpImage *image = NULL;
|
2014-07-07 00:46:25 +02:00
|
|
|
gchar *path = NULL;
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
if (! file_proc->handles_uri)
|
|
|
|
path = g_file_get_path (file);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
if (! path)
|
|
|
|
path = g_file_get_uri (file);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2006-04-26 09:13:47 +00:00
|
|
|
return_vals =
|
|
|
|
gimp_pdb_execute_procedure_by_name (gimp->pdb,
|
2007-12-02 18:05:54 +00:00
|
|
|
context, progress, error,
|
2009-08-29 12:40:40 +02:00
|
|
|
gimp_object_get_name (procedure),
|
2014-07-07 00:46:25 +02:00
|
|
|
G_TYPE_STRING, path,
|
2006-04-26 09:13:47 +00:00
|
|
|
GIMP_TYPE_INT32, size,
|
|
|
|
G_TYPE_NONE);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
g_free (path);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
status = g_value_get_enum (gimp_value_array_index (return_vals, 0));
|
2004-11-18 19:00:02 +00:00
|
|
|
|
2008-11-10 08:21:36 +00:00
|
|
|
if (status == GIMP_PDB_SUCCESS &&
|
2012-05-04 00:50:23 +02:00
|
|
|
GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1)))
|
2004-11-18 19:00:02 +00:00
|
|
|
{
|
2012-05-04 00:50:23 +02:00
|
|
|
image = gimp_value_get_image (gimp_value_array_index (return_vals, 1),
|
|
|
|
gimp);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
if (gimp_value_array_length (return_vals) >= 3 &&
|
|
|
|
G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 2)) &&
|
|
|
|
G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 3)))
|
2006-03-30 13:00:17 +00:00
|
|
|
{
|
2012-05-04 00:50:23 +02:00
|
|
|
*image_width =
|
|
|
|
MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 2)));
|
2008-11-10 08:21:36 +00:00
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
*image_height =
|
|
|
|
MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 3)));
|
|
|
|
|
|
|
|
if (gimp_value_array_length (return_vals) >= 5 &&
|
|
|
|
G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 4)))
|
2008-11-10 08:21:36 +00:00
|
|
|
{
|
2012-05-04 00:50:23 +02:00
|
|
|
gint value = g_value_get_int (gimp_value_array_index (return_vals, 4));
|
2008-11-10 08:21:36 +00:00
|
|
|
|
2012-04-11 21:54:23 +02:00
|
|
|
switch (value)
|
2008-11-10 08:21:36 +00:00
|
|
|
{
|
2012-04-11 21:54:23 +02:00
|
|
|
case GIMP_RGB_IMAGE:
|
2013-06-23 16:51:24 +02:00
|
|
|
*format = gimp_babl_format (GIMP_RGB,
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 14:23:01 +02:00
|
|
|
GIMP_PRECISION_U8_NON_LINEAR,
|
|
|
|
FALSE, NULL);
|
2012-04-11 21:54:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
2013-06-23 16:51:24 +02:00
|
|
|
*format = gimp_babl_format (GIMP_RGB,
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 14:23:01 +02:00
|
|
|
GIMP_PRECISION_U8_NON_LINEAR,
|
|
|
|
TRUE, NULL);
|
2012-04-11 21:54:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
2013-06-23 16:51:24 +02:00
|
|
|
*format = gimp_babl_format (GIMP_GRAY,
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 14:23:01 +02:00
|
|
|
GIMP_PRECISION_U8_NON_LINEAR,
|
|
|
|
FALSE, NULL);
|
2012-04-11 21:54:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
2013-06-23 16:51:24 +02:00
|
|
|
*format = gimp_babl_format (GIMP_GRAY,
|
Initial space invasion commit in GIMP
All babl formats now have a space equivalent to a color profile,
determining the format's primaries and TRCs. This commit makes GIMP
aware of this.
libgimp:
- enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA
as deprecated aliases, add PERCEPTUAL values so we now have LINEAR,
NON_LINEAR and PERCPTUAL for each encoding, matching the babl
encoding variants RGB, R'G'B' and R~G~B~.
- gimp_color_transform_can_gegl_copy() now returns TRUE if both
profiles can return a babl space, increasing the amount of fast babl
color conversions significantly.
- TODO: no solution yet for getting libgimp drawable proxy buffers in
the right format with space.
plug-ins:
- follow the GimpPrecision change.
- TODO: everything else unchanged and partly broken or sub-optimal,
like setting a new image's color profile too late.
app:
- add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as
replacement for all "linear" booleans.
- change gimp-babl functions to take babl spaces and GimpTRCType
parameters and support all sorts of new perceptual ~ formats.
- a lot of places changed in the early days of goat invasion didn't
take advantage of gimp-babl utility functions and constructed
formats manually. They all needed revisiting and many now use much
simpler code calling gimp-babl API.
- change gimp_babl_format_get_color_profile() to really extract a
newly allocated color profile from the format, and add
gimp_babl_get_builtin_color_profile() which does the same as
gimp_babl_format_get_color_profile() did before. Visited all callers
to decide whether they are looking for the format's actual profile,
or for one of the builtin profiles, simplifying code that only needs
builtin profiles.
- drawables have a new get_space_api(), get_linear() is now get_trc().
- images now have a "layer space" and an API to get it,
gimp_image_get_layer_format() returns formats in that space.
- an image's layer space is created from the image's color profile,
change gimpimage-color-profile to deal with that correctly
- change many babl_format() calls to babl_format_with_space() and take
the space from passed formats or drawables
- add function gimp_layer_fix_format_space() which replaces the
layer's buffer with one that has the image's layer format, but
doesn't change pixel values
- use gimp_layer_fix_format_space() to make sure layers loaded from
XCF and created by plug-ins have the right space when added to the
image, because it's impossible to always assign the right space upon
layer creation
- "assign color profile" and "discard color profile" now require use
of gimp_layer_fix_format_space() too because the profile is now
embedded in all formats via the space. Add
gimp_image_assign_color_profile() which does all that and call it
instead of a simple gimp_image_set_color_profile(), also from the
PDB set-color-profile functions, which are essentially "assign" and
"discard" calls.
- generally, make sure a new image's color profile is set before
adding layers to it, gimp_image_set_color_profile() is more than
before considered know-what-you-are-doing API.
- take special precaution in all places that call
gimp_drawable_convert_type(), we now must pass a new_profile from
all callers that convert layers within the same image (such as
image_convert_type, image_convert_precision), because the layer's
new space can't be determined from the image's layer format during
the call.
- change all "linear" properties to "trc", in all config objects like
for levels and curves, in the histogram, in the widgets. This results
in some GUI that now has three choices instead of two.
TODO: we might want to reduce that back to two later.
- keep "linear" boolean properties around as compat if needed for file
pasring, but always convert the parsed parsed boolean to
GimpTRCType.
- TODO: the image's "enable color management" switch is currently
broken, will fix that in another commit.
2018-07-21 14:23:01 +02:00
|
|
|
GIMP_PRECISION_U8_NON_LINEAR,
|
|
|
|
TRUE, NULL);
|
2012-04-11 21:54:23 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
{
|
|
|
|
const Babl *rgb;
|
|
|
|
const Babl *rgba;
|
|
|
|
|
|
|
|
babl_new_palette ("-gimp-indexed-format-dummy",
|
|
|
|
&rgb, &rgba);
|
|
|
|
|
|
|
|
if (value == GIMP_INDEXED_IMAGE)
|
|
|
|
*format = rgb;
|
|
|
|
else
|
|
|
|
*format = rgba;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2008-11-10 08:21:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
if (gimp_value_array_length (return_vals) >= 6 &&
|
|
|
|
G_VALUE_HOLDS_INT (gimp_value_array_index (return_vals, 5)))
|
2008-11-10 08:21:36 +00:00
|
|
|
{
|
2012-05-04 00:50:23 +02:00
|
|
|
*num_layers =
|
|
|
|
MAX (0, g_value_get_int (gimp_value_array_index (return_vals, 5)));
|
2008-11-10 08:21:36 +00:00
|
|
|
}
|
2006-03-30 13:00:17 +00:00
|
|
|
}
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2006-03-30 13:00:17 +00:00
|
|
|
if (image)
|
|
|
|
{
|
2007-04-17 15:54:01 +00:00
|
|
|
file_open_sanitize_image (image, FALSE);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2017-05-04 23:22:37 +02:00
|
|
|
*mime_type = g_slist_nth_data (file_proc->mime_types_list, 0);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2006-07-19 06:50:34 +00:00
|
|
|
#ifdef GIMP_UNSTABLE
|
2006-03-30 13:00:17 +00:00
|
|
|
g_printerr ("opened thumbnail at %d x %d\n",
|
2007-12-25 16:21:40 +00:00
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image));
|
2006-07-19 06:50:34 +00:00
|
|
|
#endif
|
2006-03-30 13:00:17 +00:00
|
|
|
}
|
2004-11-13 17:06:06 +00:00
|
|
|
}
|
2006-03-30 13:00:17 +00:00
|
|
|
|
2012-05-04 00:50:23 +02:00
|
|
|
gimp_value_array_unref (return_vals);
|
2006-03-30 13:00:17 +00:00
|
|
|
|
|
|
|
return image;
|
2004-11-13 17:06:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
GimpImage *
|
|
|
|
file_open_with_display (Gimp *gimp,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context,
|
2004-08-10 18:47:21 +00:00
|
|
|
GimpProgress *progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file,
|
2007-04-17 15:54:01 +00:00
|
|
|
gboolean as_new,
|
2018-04-29 17:27:47 +02:00
|
|
|
GObject *monitor,
|
2002-04-19 14:09:53 +00:00
|
|
|
GimpPDBStatusType *status,
|
|
|
|
GError **error)
|
2001-11-10 19:35:21 +00:00
|
|
|
{
|
2004-08-10 18:47:21 +00:00
|
|
|
return file_open_with_proc_and_display (gimp, context, progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
file, file, as_new, NULL,
|
2018-04-29 17:27:47 +02:00
|
|
|
monitor,
|
2007-04-17 15:54:01 +00:00
|
|
|
status, error);
|
2001-11-10 19:35:21 +00:00
|
|
|
}
|
|
|
|
|
2002-04-19 14:09:53 +00:00
|
|
|
GimpImage *
|
2006-04-05 08:38:33 +00:00
|
|
|
file_open_with_proc_and_display (Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file,
|
|
|
|
GFile *entered_file,
|
2007-04-17 15:54:01 +00:00
|
|
|
gboolean as_new,
|
2006-04-05 08:38:33 +00:00
|
|
|
GimpPlugInProcedure *file_proc,
|
2018-04-29 17:27:47 +02:00
|
|
|
GObject *monitor,
|
2006-04-05 08:38:33 +00:00
|
|
|
GimpPDBStatusType *status,
|
|
|
|
GError **error)
|
2001-11-10 19:35:21 +00:00
|
|
|
{
|
2006-03-28 17:08:36 +00:00
|
|
|
GimpImage *image;
|
2004-05-14 00:01:11 +00:00
|
|
|
const gchar *mime_type = NULL;
|
2002-04-19 14:09:53 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2004-04-14 23:37:34 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-08-10 18:47:21 +00:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2014-07-07 00:46:25 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
|
|
|
g_return_val_if_fail (G_IS_FILE (entered_file), NULL);
|
2018-04-29 17:27:47 +02:00
|
|
|
g_return_val_if_fail (monitor == NULL || G_IS_OBJECT (monitor), NULL);
|
2002-04-19 14:09:53 +00:00
|
|
|
g_return_val_if_fail (status != NULL, NULL);
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
image = file_open_image (gimp, context, progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
file,
|
|
|
|
entered_file,
|
2007-04-17 15:54:01 +00:00
|
|
|
as_new,
|
2006-03-30 13:00:17 +00:00
|
|
|
file_proc,
|
|
|
|
GIMP_RUN_INTERACTIVE,
|
|
|
|
status,
|
|
|
|
&mime_type,
|
|
|
|
error);
|
2002-04-19 14:09:53 +00:00
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
if (image)
|
2001-11-10 19:35:21 +00:00
|
|
|
{
|
2011-02-07 00:50:54 +01:00
|
|
|
/* If the file was imported we want to set the layer name to the
|
|
|
|
* file name. For now, assume that multi-layered imported images
|
|
|
|
* have named the layers already, so only rename the layer of
|
|
|
|
* single-layered imported files. Note that this will also
|
|
|
|
* rename already named layers from e.g. single-layered PSD
|
|
|
|
* files. To solve this properly, we would need new file plug-in
|
|
|
|
* API.
|
|
|
|
*/
|
2011-11-28 01:32:49 +01:00
|
|
|
if (! file_proc)
|
|
|
|
file_proc = gimp_image_get_load_proc (image);
|
|
|
|
|
2011-02-07 00:50:54 +01:00
|
|
|
if (file_open_file_proc_is_import (file_proc) &&
|
|
|
|
gimp_image_get_n_layers (image) == 1)
|
|
|
|
{
|
2014-07-07 00:46:25 +02:00
|
|
|
GimpObject *layer = gimp_image_get_layer_iter (image)->data;
|
|
|
|
gchar *basename;
|
|
|
|
|
|
|
|
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2011-02-07 00:50:54 +01:00
|
|
|
|
|
|
|
gimp_item_rename (GIMP_ITEM (layer), basename, NULL);
|
|
|
|
gimp_image_undo_free (image);
|
|
|
|
gimp_image_clean_all (image);
|
2011-02-07 00:52:34 +01:00
|
|
|
|
|
|
|
g_free (basename);
|
2011-02-07 00:50:54 +01:00
|
|
|
}
|
|
|
|
|
2014-05-02 20:20:46 +02:00
|
|
|
if (gimp_create_display (image->gimp, image, GIMP_UNIT_PIXEL, 1.0,
|
2018-04-29 17:27:47 +02:00
|
|
|
monitor))
|
2011-05-17 14:55:57 +02:00
|
|
|
{
|
|
|
|
/* the display owns the image now */
|
|
|
|
g_object_unref (image);
|
|
|
|
}
|
2001-11-10 19:35:21 +00:00
|
|
|
|
2007-04-17 15:54:01 +00:00
|
|
|
if (! as_new)
|
2003-11-27 12:28:46 +00:00
|
|
|
{
|
2007-04-17 15:54:01 +00:00
|
|
|
GimpDocumentList *documents = GIMP_DOCUMENT_LIST (gimp->documents);
|
|
|
|
GimpImagefile *imagefile;
|
2014-07-07 23:56:56 +02:00
|
|
|
GFile *any_file;
|
2007-04-17 15:54:01 +00:00
|
|
|
|
2014-07-05 12:51:54 +02:00
|
|
|
imagefile = gimp_document_list_add_file (documents, file, mime_type);
|
2007-04-17 15:54:01 +00:00
|
|
|
|
2014-07-31 12:22:27 +02:00
|
|
|
/* can only create a thumbnail if the passed file and the
|
|
|
|
* resulting image's file match. Use any_file() here so we
|
2012-07-13 23:50:07 +02:00
|
|
|
* create thumbnails for both XCF and imported images.
|
2007-04-17 15:54:01 +00:00
|
|
|
*/
|
2014-07-07 23:56:56 +02:00
|
|
|
any_file = gimp_image_get_any_file (image);
|
2012-07-13 23:50:07 +02:00
|
|
|
|
2014-07-07 23:56:56 +02:00
|
|
|
if (any_file && g_file_equal (file, any_file))
|
2004-10-23 15:30:39 +00:00
|
|
|
{
|
2007-04-17 15:54:01 +00:00
|
|
|
/* no need to save a thumbnail if there's a good one already */
|
|
|
|
if (! gimp_imagefile_check_thumbnail (imagefile))
|
|
|
|
{
|
2013-05-26 21:26:08 +02:00
|
|
|
gimp_imagefile_save_thumbnail (imagefile, mime_type, image,
|
|
|
|
NULL);
|
2007-04-17 15:54:01 +00:00
|
|
|
}
|
2004-10-23 15:30:39 +00:00
|
|
|
}
|
2007-04-17 15:54:01 +00:00
|
|
|
}
|
2004-09-28 12:40:34 +00:00
|
|
|
|
2008-10-17 12:03:08 +00:00
|
|
|
/* announce that we opened this image */
|
2014-07-07 00:46:25 +02:00
|
|
|
gimp_image_opened (image->gimp, file);
|
2001-11-10 19:35:21 +00:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:08:36 +00:00
|
|
|
return image;
|
2001-11-10 19:35:21 +00:00
|
|
|
}
|
2004-06-28 21:42:19 +00:00
|
|
|
|
2006-11-03 17:12:27 +00:00
|
|
|
GList *
|
|
|
|
file_open_layers (Gimp *gimp,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpProgress *progress,
|
|
|
|
GimpImage *dest_image,
|
|
|
|
gboolean merge_visible,
|
2014-07-07 00:46:25 +02:00
|
|
|
GFile *file,
|
2006-11-03 17:12:27 +00:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpPlugInProcedure *file_proc,
|
|
|
|
GimpPDBStatusType *status,
|
|
|
|
GError **error)
|
2004-06-28 21:42:19 +00:00
|
|
|
{
|
2004-11-10 21:48:17 +00:00
|
|
|
GimpImage *new_image;
|
2006-11-03 17:12:27 +00:00
|
|
|
GList *layers = NULL;
|
2004-11-10 21:48:17 +00:00
|
|
|
const gchar *mime_type = NULL;
|
2004-06-28 21:42:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
2004-08-10 18:47:21 +00:00
|
|
|
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
2004-06-28 21:42:19 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (dest_image), NULL);
|
2014-07-07 00:46:25 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), NULL);
|
2004-06-28 21:42:19 +00:00
|
|
|
g_return_val_if_fail (status != NULL, NULL);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
|
|
|
|
2004-11-10 21:48:17 +00:00
|
|
|
new_image = file_open_image (gimp, context, progress,
|
2014-07-07 00:46:25 +02:00
|
|
|
file, file, FALSE,
|
2006-03-03 19:51:20 +00:00
|
|
|
file_proc,
|
|
|
|
run_mode,
|
2004-11-10 21:48:17 +00:00
|
|
|
status, &mime_type, error);
|
2004-06-28 21:42:19 +00:00
|
|
|
|
|
|
|
if (new_image)
|
|
|
|
{
|
2009-08-22 09:00:18 +02:00
|
|
|
gint n_visible = 0;
|
2004-06-28 21:42:19 +00:00
|
|
|
|
|
|
|
gimp_image_undo_disable (new_image);
|
|
|
|
|
2009-08-22 09:00:18 +02:00
|
|
|
layers = file_open_get_layers (new_image, merge_visible, &n_visible);
|
2004-06-28 21:42:19 +00:00
|
|
|
|
2006-11-03 17:12:27 +00:00
|
|
|
if (merge_visible && n_visible > 1)
|
2004-06-28 21:42:19 +00:00
|
|
|
{
|
2006-11-03 17:12:27 +00:00
|
|
|
GimpLayer *layer;
|
|
|
|
|
|
|
|
g_list_free (layers);
|
|
|
|
|
|
|
|
layer = gimp_image_merge_visible_layers (new_image, context,
|
2011-02-14 09:45:59 +01:00
|
|
|
GIMP_CLIP_TO_IMAGE,
|
|
|
|
FALSE, FALSE);
|
2006-11-03 17:12:27 +00:00
|
|
|
|
|
|
|
layers = g_list_prepend (NULL, layer);
|
|
|
|
}
|
2004-06-28 21:42:19 +00:00
|
|
|
|
2006-11-03 17:12:27 +00:00
|
|
|
if (layers)
|
|
|
|
{
|
2014-07-07 00:46:25 +02:00
|
|
|
gchar *basename;
|
2006-12-11 18:39:12 +00:00
|
|
|
|
2014-07-07 00:46:25 +02:00
|
|
|
basename = g_path_get_basename (gimp_file_get_utf8_name (file));
|
2008-01-08 11:01:34 +00:00
|
|
|
file_open_convert_items (dest_image, basename, layers);
|
2006-12-11 18:39:12 +00:00
|
|
|
g_free (basename);
|
|
|
|
|
2014-07-05 12:51:54 +02:00
|
|
|
gimp_document_list_add_file (GIMP_DOCUMENT_LIST (gimp->documents),
|
|
|
|
file, mime_type);
|
2004-06-28 21:42:19 +00:00
|
|
|
}
|
2004-07-15 10:37:03 +00:00
|
|
|
else
|
|
|
|
{
|
2008-11-04 12:33:09 +00:00
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
2016-12-21 04:05:32 +01:00
|
|
|
_("Image doesn't contain any layers"));
|
2004-07-15 10:37:03 +00:00
|
|
|
*status = GIMP_PDB_EXECUTION_ERROR;
|
2008-01-08 11:01:34 +00:00
|
|
|
}
|
2004-06-28 21:42:19 +00:00
|
|
|
|
|
|
|
g_object_unref (new_image);
|
|
|
|
}
|
|
|
|
|
2006-11-03 17:12:27 +00:00
|
|
|
return g_list_reverse (layers);
|
2004-06-28 21:42:19 +00:00
|
|
|
}
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
|
2007-01-22 21:39:57 +00:00
|
|
|
/* This function is called for filenames passed on the command-line
|
|
|
|
* or from the D-Bus service.
|
|
|
|
*/
|
2007-03-27 19:40:31 +00:00
|
|
|
gboolean
|
2014-07-07 01:02:54 +02:00
|
|
|
file_open_from_command_line (Gimp *gimp,
|
|
|
|
GFile *file,
|
|
|
|
gboolean as_new,
|
2018-04-29 17:27:47 +02:00
|
|
|
GObject *monitor)
|
2014-05-02 20:20:46 +02:00
|
|
|
|
2007-01-22 21:39:57 +00:00
|
|
|
{
|
2014-07-07 01:02:54 +02:00
|
|
|
GimpImage *image;
|
|
|
|
GimpObject *display;
|
|
|
|
GimpPDBStatusType status;
|
|
|
|
gboolean success = FALSE;
|
|
|
|
GError *error = NULL;
|
2007-01-22 21:39:57 +00:00
|
|
|
|
2007-03-27 19:40:31 +00:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
|
2014-07-07 01:02:54 +02:00
|
|
|
g_return_val_if_fail (G_IS_FILE (file), FALSE);
|
2018-04-29 17:27:47 +02:00
|
|
|
g_return_val_if_fail (monitor == NULL || G_IS_OBJECT (monitor), FALSE);
|
2007-01-22 21:39:57 +00:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
display = gimp_get_empty_display (gimp);
|
2007-03-27 19:40:31 +00:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
/* show the progress in the last opened display, see bug #704896 */
|
|
|
|
if (! display)
|
|
|
|
display = gimp_context_get_display (gimp_get_user_context (gimp));
|
2007-01-22 21:39:57 +00:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
if (display)
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (display), (gpointer) &display);
|
2013-11-20 23:17:40 +01:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
image = file_open_with_display (gimp,
|
|
|
|
gimp_get_user_context (gimp),
|
|
|
|
GIMP_PROGRESS (display),
|
|
|
|
file, as_new,
|
2018-04-29 17:27:47 +02:00
|
|
|
monitor,
|
2014-07-07 01:02:54 +02:00
|
|
|
&status, &error);
|
2013-07-04 21:05:25 +02:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
if (image)
|
|
|
|
{
|
|
|
|
success = TRUE;
|
2014-07-07 00:46:25 +02:00
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
g_object_set_data_full (G_OBJECT (gimp), GIMP_FILE_OPEN_LAST_FILE_KEY,
|
|
|
|
g_object_ref (file),
|
|
|
|
(GDestroyNotify) g_object_unref);
|
2007-01-22 21:39:57 +00:00
|
|
|
}
|
2014-07-07 01:02:54 +02:00
|
|
|
else if (status != GIMP_PDB_CANCEL && display)
|
2007-03-27 19:40:31 +00:00
|
|
|
{
|
2014-07-07 01:02:54 +02:00
|
|
|
gimp_message (gimp, G_OBJECT (display), GIMP_MESSAGE_ERROR,
|
|
|
|
_("Opening '%s' failed: %s"),
|
|
|
|
gimp_file_get_utf8_name (file), error->message);
|
2007-03-27 19:40:31 +00:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
|
2014-07-07 01:02:54 +02:00
|
|
|
if (display)
|
|
|
|
g_object_remove_weak_pointer (G_OBJECT (display), (gpointer) &display);
|
|
|
|
|
2007-03-27 19:40:31 +00:00
|
|
|
return success;
|
2007-01-22 21:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-13 17:06:06 +00:00
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
2007-04-17 15:54:01 +00:00
|
|
|
file_open_sanitize_image (GimpImage *image,
|
|
|
|
gboolean as_new)
|
2004-11-13 17:06:06 +00:00
|
|
|
{
|
2007-04-17 15:54:01 +00:00
|
|
|
if (as_new)
|
2014-07-07 23:56:56 +02:00
|
|
|
gimp_image_set_file (image, NULL);
|
2007-04-17 15:54:01 +00:00
|
|
|
|
2004-11-13 17:06:06 +00:00
|
|
|
/* clear all undo steps */
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_free (image);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
|
|
|
/* make sure that undo is enabled */
|
2010-02-05 09:19:43 +01:00
|
|
|
while (! gimp_image_undo_is_enabled (image))
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_undo_thaw (image);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2009-07-03 22:51:11 +02:00
|
|
|
/* Set the image to clean. Note that export dirtiness is not set to
|
|
|
|
* clean here; we can only consider export clean after the first
|
|
|
|
* export
|
|
|
|
*/
|
2006-03-28 17:08:36 +00:00
|
|
|
gimp_image_clean_all (image);
|
2004-11-13 17:06:06 +00:00
|
|
|
|
2016-06-16 00:57:31 +02:00
|
|
|
/* Make sure the projection is completely constructed from valid
|
|
|
|
* layers, this is needed in case something triggers projection or
|
|
|
|
* image preview creation before all layers are loaded, see bug #767663.
|
|
|
|
*/
|
|
|
|
gimp_image_invalidate (image, 0, 0,
|
|
|
|
gimp_image_get_width (image),
|
|
|
|
gimp_image_get_height (image));
|
|
|
|
|
2015-09-09 21:21:20 +02:00
|
|
|
/* Make sure all image states are up-to-date */
|
2007-06-21 10:09:27 +00:00
|
|
|
gimp_image_flush (image);
|
2004-11-13 17:06:06 +00:00
|
|
|
}
|
2006-10-27 13:52:40 +00:00
|
|
|
|
2008-01-08 11:01:34 +00:00
|
|
|
/* Converts items from one image to another */
|
|
|
|
static void
|
|
|
|
file_open_convert_items (GimpImage *dest_image,
|
|
|
|
const gchar *basename,
|
|
|
|
GList *items)
|
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
for (list = items; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpItem *src = list->data;
|
|
|
|
GimpItem *item;
|
|
|
|
|
2008-01-08 11:46:15 +00:00
|
|
|
item = gimp_item_convert (src, dest_image, G_TYPE_FROM_INSTANCE (src));
|
2008-01-08 11:01:34 +00:00
|
|
|
|
|
|
|
if (g_list_length (items) == 1)
|
|
|
|
{
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (item), basename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-22 10:34:15 +02:00
|
|
|
gimp_object_set_name (GIMP_OBJECT (item),
|
2009-08-31 22:47:18 +02:00
|
|
|
gimp_object_get_name (src));
|
2008-01-08 11:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
list->data = item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-22 09:00:18 +02:00
|
|
|
static GList *
|
2016-05-19 23:51:44 +02:00
|
|
|
file_open_get_layers (GimpImage *image,
|
|
|
|
gboolean merge_visible,
|
|
|
|
gint *n_visible)
|
2009-08-22 09:00:18 +02:00
|
|
|
{
|
|
|
|
GList *iter = NULL;
|
|
|
|
GList *layers = NULL;
|
|
|
|
|
|
|
|
for (iter = gimp_image_get_layer_iter (image);
|
|
|
|
iter;
|
|
|
|
iter = g_list_next (iter))
|
|
|
|
{
|
|
|
|
GimpItem *item = iter->data;
|
|
|
|
|
|
|
|
if (! merge_visible)
|
|
|
|
layers = g_list_prepend (layers, item);
|
|
|
|
|
|
|
|
if (gimp_item_get_visible (item))
|
|
|
|
{
|
|
|
|
if (n_visible)
|
|
|
|
(*n_visible)++;
|
|
|
|
|
|
|
|
if (! layers)
|
|
|
|
layers = g_list_prepend (layers, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return layers;
|
|
|
|
}
|
|
|
|
|
2009-04-23 20:44:12 +02:00
|
|
|
static gboolean
|
2016-01-03 20:05:27 +01:00
|
|
|
file_open_file_proc_is_import (GimpPlugInProcedure *file_proc)
|
2009-04-23 20:44:12 +02:00
|
|
|
{
|
|
|
|
return !(file_proc &&
|
2017-05-04 23:22:37 +02:00
|
|
|
file_proc->mime_types &&
|
|
|
|
strcmp (file_proc->mime_types, "image/x-xcf") == 0);
|
2009-04-23 20:44:12 +02:00
|
|
|
}
|