mirror of https://github.com/GNOME/gimp.git
plug-ins: Load PSD metadata in JPEG plug-in
This adds the PSD metadata plug-in procedure call to the JPEG plug-in, as part of implementing issue #7549. Also implements the import half of issue #1842. JPEGs only store image-level metadata like paths.
This commit is contained in:
parent
7b6d229be8
commit
b5f80f7a14
|
@ -55,6 +55,7 @@ load_image (GFile *file,
|
|||
GimpRunMode runmode,
|
||||
gboolean preview,
|
||||
gboolean *resolution_loaded,
|
||||
gboolean *ps_metadata_loaded,
|
||||
GError **error)
|
||||
{
|
||||
GimpImage * volatile image;
|
||||
|
@ -67,14 +68,16 @@ load_image (GFile *file,
|
|||
guchar **rowbuf;
|
||||
GimpImageBaseType image_type;
|
||||
GimpImageType layer_type;
|
||||
GeglBuffer *buffer = NULL;
|
||||
GeglBuffer *buffer = NULL;
|
||||
const Babl *format;
|
||||
const Babl *space;
|
||||
const gchar *encoding;
|
||||
const gchar *layer_name = NULL;
|
||||
GimpColorProfile *cmyk_profile = NULL;
|
||||
const gchar *layer_name = NULL;
|
||||
GimpColorProfile *cmyk_profile = NULL;
|
||||
gint tile_height;
|
||||
gint i;
|
||||
guchar *photoshop_data = NULL;
|
||||
guint photoshop_len = 0;
|
||||
|
||||
/* We set up the normal JPEG error routines. */
|
||||
cinfo.err = jpeg_std_error (&jerr.pub);
|
||||
|
@ -139,6 +142,9 @@ load_image (GFile *file,
|
|||
|
||||
/* - step 2.3: tell the lib to save APP2 data (ICC profiles) */
|
||||
jpeg_save_markers (&cinfo, JPEG_APP0 + 2, 0xffff);
|
||||
|
||||
/* - step 2.4: tell the lib to save APP13 data (clipping path) */
|
||||
jpeg_save_markers (&cinfo, JPEG_APP0 + 13, 0xffff);
|
||||
}
|
||||
|
||||
/* Step 3: read file parameters with jpeg_read_header() */
|
||||
|
@ -265,6 +271,19 @@ load_image (GFile *file,
|
|||
#ifdef GIMP_UNSTABLE
|
||||
g_print ("jpeg-load: found Exif block (%d bytes)\n",
|
||||
(gint) (len - sizeof (JPEG_APP_HEADER_EXIF)));
|
||||
#endif
|
||||
}
|
||||
else if ((marker->marker == JPEG_APP0 + 13))
|
||||
{
|
||||
photoshop_data = g_new (guchar, len);
|
||||
photoshop_len = len;
|
||||
memcpy (photoshop_data, (guchar *) marker->data, len);
|
||||
|
||||
*ps_metadata_loaded = TRUE;
|
||||
|
||||
#ifdef GIMP_UNSTABLE
|
||||
g_print ("jpeg-load: found Photoshop block (%d bytes) %s\n",
|
||||
(gint) (len - sizeof (JPEG_APP_HEADER_EXIF)), data);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -451,6 +470,47 @@ load_image (GFile *file,
|
|||
|
||||
gimp_image_insert_layer (image, layer, NULL, 0);
|
||||
|
||||
/* Step 9: Load PSD-format metadata if applicable */
|
||||
if (photoshop_len > 0)
|
||||
{
|
||||
FILE *fp;
|
||||
GFile *temp_file = NULL;
|
||||
GimpValueArray *return_vals = NULL;
|
||||
|
||||
temp_file = gimp_temp_file ("tmp");
|
||||
fp = g_fopen (g_file_peek_path (temp_file), "wb");
|
||||
|
||||
if (! fp)
|
||||
{
|
||||
g_message (_("Error trying to open temporary %s file '%s' "
|
||||
"for jpeg metadata loading: %s"),
|
||||
"tmp",
|
||||
gimp_file_get_utf8_name (temp_file),
|
||||
g_strerror (errno));
|
||||
}
|
||||
|
||||
fwrite (photoshop_data + (sizeof (JPEG_APP_HEADER_EXIF) * 2),
|
||||
sizeof (guchar), photoshop_len - sizeof (JPEG_APP_HEADER_EXIF),
|
||||
fp);
|
||||
fclose (fp);
|
||||
|
||||
g_free (photoshop_data);
|
||||
|
||||
return_vals =
|
||||
gimp_pdb_run_procedure (gimp_get_pdb (),
|
||||
"file-psd-load-metadata",
|
||||
GIMP_TYPE_RUN_MODE, GIMP_RUN_NONINTERACTIVE,
|
||||
G_TYPE_FILE, temp_file,
|
||||
G_TYPE_INT, photoshop_len,
|
||||
GIMP_TYPE_IMAGE, image,
|
||||
G_TYPE_BOOLEAN, FALSE,
|
||||
G_TYPE_NONE);
|
||||
|
||||
g_file_delete (temp_file, NULL, NULL);
|
||||
g_object_unref (temp_file);
|
||||
gimp_value_array_unref (return_vals);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -630,4 +690,4 @@ load_thumbnail_image (GFile *file,
|
|||
fclose (infile);
|
||||
|
||||
return image;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
#ifndef __JPEG_LOAD_H__
|
||||
#define __JPEG_LOAD_H__
|
||||
|
||||
GimpImage * load_image (GFile *file,
|
||||
GimpRunMode runmode,
|
||||
gboolean preview,
|
||||
gboolean *resolution_loaded,
|
||||
GError **error);
|
||||
GimpImage * load_image (GFile *file,
|
||||
GimpRunMode runmode,
|
||||
gboolean preview,
|
||||
gboolean *resolution_loaded,
|
||||
gboolean *ps_metadata_loaded,
|
||||
GError **error);
|
||||
|
||||
GimpImage * load_thumbnail_image (GFile *file,
|
||||
gint *width,
|
||||
|
|
|
@ -152,7 +152,7 @@ background_jpeg_save (PreviewPersistent *pp)
|
|||
|
||||
/* and load the preview */
|
||||
load_image (pp->file, GIMP_RUN_NONINTERACTIVE,
|
||||
TRUE, NULL, NULL);
|
||||
TRUE, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
/* we cleanup here (load_image doesn't run in the background) */
|
||||
|
|
|
@ -322,8 +322,9 @@ jpeg_load (GimpProcedure *procedure,
|
|||
{
|
||||
GimpValueArray *return_vals;
|
||||
GimpImage *image;
|
||||
gboolean resolution_loaded = FALSE;
|
||||
GError *error = NULL;
|
||||
gboolean resolution_loaded = FALSE;
|
||||
gboolean ps_metadata_loaded = FALSE;
|
||||
GError *error = NULL;
|
||||
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
|
@ -342,7 +343,7 @@ jpeg_load (GimpProcedure *procedure,
|
|||
}
|
||||
|
||||
image = load_image (file, run_mode, FALSE,
|
||||
&resolution_loaded, &error);
|
||||
&resolution_loaded, &ps_metadata_loaded, &error);
|
||||
|
||||
if (image)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue