Commit 325b5df4 authored by William Skaggs's avatar William Skaggs

Bill Skaggs <weskaggs@primate.ucdavis.edu>

	* gimp/plug-ins/jpeg/gimpexif.c
	* gimp/plug-ins/jpeg/gimpexif.h: new files with prototype
	interface code for metadata system.

	* gimp/plug-ins/jpeg/Makefile.am
	* gimp/plug-ins/jpeg/jpeg-exif.c
	* gimp/plug-ins/jpeg/jpeg.c: adapted to metadata interface
	as described on gimp-dev mailing list.
parent 4f698cd3
2005-01-18 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* gimp/plug-ins/jpeg/gimpexif.c
* gimp/plug-ins/jpeg/gimpexif.h: new files with prototype
interface code for metadata system.
* gimp/plug-ins/jpeg/Makefile.am
* gimp/plug-ins/jpeg/jpeg-exif.c
* gimp/plug-ins/jpeg/jpeg.c: adapted to metadata interface
as described on gimp-dev mailing list.
2005-01-18 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* libgimpwidgets/gimpwidgets.c (gimp_coordinates_callback):
......
......@@ -37,7 +37,9 @@ jpeg_SOURCES = \
jpeg.h \
jpeg-save.h \
jpeg-load.h \
jpeg-exif.c
jpeg-exif.c \
gimpexif.c \
gimpexif.h
jpeg_LDADD = \
$(libgimpui) \
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
/*
* EXIF-handling code for the metadata library.
*/
#include "config.h"
#include <stdlib.h>
#include <libgimp/gimp.h>
#ifdef HAVE_EXIF
#include <libexif/exif-data.h>
#include <libexif/exif-content.h>
#include <libexif/exif-utils.h>
#include "gimpexif.h"
/*
* gimp_metadata_store_exif:
* @image_ID: the GIMP image to work on.
* @exif_data: the Exif data that is to be stored.
*
* This function is supposed to load the "gimp-metadata" parasite
* (which is in XMP format), parse it, add the exif information,
* reformat it into XMP, and store the result as the new parasite.
* The infrastructure to do this is not yet available, so for the
* moment it does something much simpler -- it calls upon libexif
* to serialize the exif data, and stores the result in a parasite
* called "exif-data".
*/
void gimp_metadata_store_exif (gint32 image_ID,
ExifData *exif_data)
{
GimpParasite *parasite = NULL;
guchar *exif_buf = NULL;
guint exif_buf_len = 0;
exif_data_save_data (exif_data, &exif_buf, &exif_buf_len);
if (exif_buf_len > EXIF_HEADER_SIZE)
{
parasite = gimp_parasite_new ("exif-data",
GIMP_PARASITE_PERSISTENT,
exif_buf_len, exif_buf);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
free (exif_buf);
}
/*
* gimp_metadata_generate_exif:
* @image_ID: the ID of the GIMP image to work on.
*
* This function is supposed to load the "gimp-metadata" parasite
* (which is a block of XMP info), parse it, extract the exif
* values, and build an ExifData structure from them.
* The infrastructure to do this is not yet available, so for the
* moment it does something much simpler -- it loads the "exif-data"
* parasite (which is a serialized representation of the exif data),
* and calls upon libexif to parse it into an ExifData struct.
*
* returns: The reconstructed exif data, or NULL if none exists.
*/
ExifData *
gimp_metadata_generate_exif (gint32 image_ID)
{
ExifData *exif_data;
GimpParasite *parasite = gimp_image_parasite_find (image_ID,
"exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
gimp_parasite_free (parasite);
return exif_data;
}
return NULL;
}
/*
* gimp_exif_content_get_value:
* @content: ExifContent block from which to get value
* @tag: Tag whose value to get
* @value: Place to put the result
* @maxlen: Maximum size of returned string
*
* This function is a wrapper around the libexif function
* exif_content_get_value(), necessary to deal with an incompatible
* API change. It looks up the value of the specifed tag,
* returning the result as a human-readable string. Note that
* @value must be pre-allocated.
*/
const gchar *
gimp_exif_content_get_value (ExifContent *content,
ExifTag tag,
gchar *value,
gint maxlen)
{
ExifEntry *entry = exif_content_get_entry (content, tag);
if (entry)
return gimp_exif_entry_get_value (entry, value, maxlen);
else
return NULL;
}
/*
* gimp_exif_entry_get_value:
* @content: ExifEntry from which to get value
* @value: Place to put the result
* @maxlen: Maximum size of returned string
*
* This function is a wrapper around the libexif function
* exif_entry_get_value(), necessary to deal with an incompatible
* API change. It looks up the value of the specifed entry,
* returning the result as a human-readable string. Note that
* @value must be pre-allocated.
*/
const gchar *
gimp_exif_entry_get_value (ExifEntry *entry,
gchar *value,
guint maxlen)
{
#ifdef HAVE_EXIF_0_6
return exif_entry_get_value (entry, value, maxlen);
#else
strncpy (value, exif_entry_get_value (entry), maxlen);
return value;
#endif /* HAVE_EXIF_0_6 */
}
/*
* gimp_exif_data_remove_entry:
* @data: ExifData pointer
* @ifd: Index of the ifd holding the entry to be removed
* @tag: Tag of the entry to be removed
*
* This is a convenience function for removing a specified
* entry from an exif data structure. If no such entry
* exists, the function returns without doing anything.
*/
void
gimp_exif_data_remove_entry (ExifData *exif_data,
ExifIfd ifd,
ExifTag tag)
{
ExifEntry *entry = exif_content_get_entry (exif_data->ifd[ifd],
tag);
if (entry)
exif_content_remove_entry (exif_data->ifd[ifd], entry);
}
#endif /* HAVE_EXIF */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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.
*/
/*
* EXIF-handling code for the metadata library.
*/
#ifdef HAVE_EXIF
#define EXIF_HEADER_SIZE 8
void gimp_metadata_store_exif (gint32 image_ID,
ExifData *exif_data);
ExifData * gimp_metadata_generate_exif (gint32 image_ID);
const gchar * gimp_exif_content_get_value (ExifContent *content,
ExifTag tag,
gchar *value,
gint maxlen);
const gchar * gimp_exif_entry_get_value (ExifEntry *entry,
gchar *value,
guint maxlen);
void gimp_exif_data_remove_entry (ExifData *exif_data,
ExifIfd ifd,
ExifTag tag);
#endif /* HAVE_EXIF */
......@@ -24,8 +24,6 @@
#include "config.h"
#ifdef HAVE_EXIF
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
......@@ -34,6 +32,8 @@
#include <jpeglib.h>
#include <jerror.h>
#ifdef HAVE_EXIF
#include <libexif/exif-content.h>
#include <libexif/exif-data.h>
#include <libexif/exif-utils.h>
......@@ -43,23 +43,12 @@
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
#include "gimpexif.h"
#include "jpeg.h"
#include "libgimp/stdplugins-intl.h"
#define jpeg_exif_content_get_value(c,t,v,m) \
(exif_content_get_entry (c,t) ? \
jpeg_exif_entry_get_value (exif_content_get_entry (c,t),v,m) : NULL)
static void jpeg_remove_exif_entry (ExifData *exif_data,
ExifIfd ifd,
ExifTag tag);
static const gchar * jpeg_exif_entry_get_value (ExifEntry *e,
gchar *val,
guint maxlen);
static gboolean jpeg_query (const gchar *msg);
......@@ -68,83 +57,18 @@ void
jpeg_apply_exif_data_to_image (const gchar *filename,
const gint32 image_ID)
{
GimpParasite *parasite = NULL;
ExifData *exif_data = NULL;
guchar *exif_buf = NULL;
guint exif_buf_len = 0;
ExifEntry *entry;
gchar value[1000];
gint byte_order;
exif_data = exif_data_new_from_file (filename);
if (!exif_data)
return;
exif_data_save_data (exif_data, &exif_buf, &exif_buf_len);
if (exif_buf_len > EXIF_HEADER_SIZE)
{
parasite = gimp_parasite_new ("exif-data",
GIMP_PARASITE_PERSISTENT,
exif_buf_len, exif_buf);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
free (exif_buf);
gimp_metadata_store_exif (image_ID, exif_data);
byte_order = exif_data_get_byte_order (exif_data);
/* get copyright and put it in a parasite */
if (jpeg_exif_content_get_value (exif_data->ifd[EXIF_IFD_0],
EXIF_TAG_COPYRIGHT,
value, 1000))
{
parasite = gimp_parasite_new ("gimp-copyright",
/* GIMP_PARASITE_PERSISTENT */ 0,
strlen (value), value);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
/* get image artist and put it in a parasite */
if (jpeg_exif_content_get_value (exif_data->ifd[EXIF_IFD_0],
EXIF_TAG_ARTIST,
value, 1000))
{
parasite = gimp_parasite_new ("gimp-artist",
/* GIMP_PARASITE_PERSISTENT */ 0,
strlen (value), value);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
/* get user comment and put it in a parasite */
/* note that the format is undefined according to the spec */
if (jpeg_exif_content_get_value (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_USER_COMMENT,
value, 1000))
{
parasite = gimp_parasite_new ("jpeg-user-comment",
/* GIMP_PARASITE_PERSISTENT */ 0,
strlen (value), value);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
/* get image description and put it in a parasite */
/* this must be ascii, so we put it into gimp-comment */
if (jpeg_exif_content_get_value (exif_data->ifd[EXIF_IFD_0],
EXIF_TAG_IMAGE_DESCRIPTION,
value, 1000))
{
parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
strlen (value), value);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
/* get orientation and rotate image accordingly if necessary */
if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_0],
EXIF_TAG_ORIENTATION)))
......@@ -190,25 +114,6 @@ jpeg_apply_exif_data_to_image (const gchar *filename,
}
/* get Colorspace and put it in a parasite */
/* this can only be 'sRGB' or 'uncalibrated' */
if ((entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_COLOR_SPACE)))
{
gint s = exif_get_short (entry->data, byte_order);
if (s == 1)
sprintf (value, "sRGB");
else
sprintf (value, "uncalibrated");
parasite = gimp_parasite_new ("gimp-colorspace",
/* GIMP_PARASITE_PERSISTENT */ 0,
strlen (value), value);
gimp_image_parasite_attach (image_ID, parasite);
gimp_parasite_free (parasite);
}
exif_data_unref (exif_data);
}
......@@ -220,7 +125,6 @@ jpeg_setup_exif_for_save (ExifData *exif_data,
ExifRational r;
gdouble xres, yres;
ExifEntry *entry;
GimpParasite *parasite;
gint byte_order = exif_data_get_byte_order (exif_data);
/* set orientation to top - left */
......@@ -289,128 +193,26 @@ jpeg_setup_exif_for_save (ExifData *exif_data,
exif_entry_initialize (entry, EXIF_TAG_DATE_TIME);
}
/* save "gimp-comment" as the image description */
parasite = gimp_image_parasite_find (image_ID, "gimp-comment");
if (parasite)
{
entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_IMAGE_DESCRIPTION);
if (!entry)
{
entry = exif_entry_new ();
exif_content_add_entry (exif_data->ifd[EXIF_IFD_EXIF],
entry);
exif_entry_initialize (entry, EXIF_TAG_IMAGE_DESCRIPTION);
entry->data = g_strndup (parasite->data, parasite->size);
entry->size = parasite->size;
entry->components = parasite->size;
}
gimp_parasite_free (parasite);
}
parasite = gimp_image_parasite_find (image_ID, "gimp-copyright");
if (parasite)
{
entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_COPYRIGHT);
if (!entry)
{
entry = exif_entry_new ();
exif_content_add_entry (exif_data->ifd[EXIF_IFD_EXIF],
entry);
exif_entry_initialize (entry, EXIF_TAG_COPYRIGHT);
entry->data = g_strndup (parasite->data, parasite->size);
entry->size = parasite->size;
entry->components = parasite->size;
}
gimp_parasite_free (parasite);
}
parasite = gimp_image_parasite_find (image_ID, "gimp-artist");
if (parasite)
{
entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_ARTIST);
if (!entry)
{
entry = exif_entry_new ();
exif_content_add_entry (exif_data->ifd[EXIF_IFD_EXIF],
entry);
exif_entry_initialize (entry, EXIF_TAG_ARTIST);
entry->data = g_strndup (parasite->data, parasite->size);
entry->size = parasite->size;
entry->components = parasite->size;
}
gimp_parasite_free (parasite);
}
parasite = gimp_image_parasite_find (image_ID, "jpeg-user-comment");
if (parasite)
{
entry = exif_content_get_entry (exif_data->ifd[EXIF_IFD_EXIF],
EXIF_TAG_USER_COMMENT);
if (!entry)
{
entry = exif_entry_new ();
exif_content_add_entry (exif_data->ifd[EXIF_IFD_EXIF],
entry);
exif_entry_initialize (entry, EXIF_TAG_USER_COMMENT);
entry->data = g_strndup (parasite->data, parasite->size);
entry->size = parasite->size;
entry->components = parasite->size;
}
gimp_parasite_free (parasite);
}
/* should set components configuration, don't know how */
/*
*remove entries that don't apply to jpeg
*(may have come from tiff or raw)
*/
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_COMPRESSION);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_IMAGE_WIDTH);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_IMAGE_LENGTH);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_BITS_PER_SAMPLE);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_SAMPLES_PER_PIXEL);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_PHOTOMETRIC_INTERPRETATION);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_STRIP_OFFSETS);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_PLANAR_CONFIGURATION);
jpeg_remove_exif_entry(exif_data, EXIF_IFD_0, EXIF_TAG_YCBCR_SUB_SAMPLING);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_COMPRESSION);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_IMAGE_WIDTH);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_IMAGE_LENGTH);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_BITS_PER_SAMPLE);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_SAMPLES_PER_PIXEL);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_PHOTOMETRIC_INTERPRETATION);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_STRIP_OFFSETS);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_PLANAR_CONFIGURATION);
gimp_exif_data_remove_entry(exif_data, EXIF_IFD_0, EXIF_TAG_YCBCR_SUB_SAMPLING);
/* should set thumbnail attributes */
}
static void
jpeg_remove_exif_entry (ExifData *exif_data,
ExifIfd ifd,
ExifTag tag)
{
ExifEntry *entry = exif_content_get_entry (exif_data->ifd[ifd],
tag);
if (entry)
exif_content_remove_entry (exif_data->ifd[ifd], entry);
}
static const gchar *
jpeg_exif_entry_get_value (ExifEntry *e,
gchar *val,
guint maxlen)
{
#ifdef HAVE_EXIF_0_6
return exif_entry_get_value (e, val, maxlen);
#else
strncpy (val, exif_entry_get_value (e), maxlen);
return val;
#endif /* HAVE_EXIF_0_6 */
}
static gboolean
jpeg_query (const gchar *msg)
{
......
......@@ -37,7 +37,7 @@
#include "jpeg.h"
#include "jpeg-load.h"
#include "jpeg-save.h"
#include "gimpexif.h"
/* Declare local functions.
*/
......@@ -309,16 +309,9 @@ run (const gchar *name,
#ifdef HAVE_EXIF
parasite = gimp_image_parasite_find (orig_image_ID, "exif-data");
if (parasite)
{
exif_data = exif_data_new_from_data (gimp_parasite_data (parasite),
gimp_parasite_data_size (parasite));
jpeg_setup_exif_for_save (exif_data, orig_image_ID);
gimp_parasite_free (parasite);
}
exif_data = gimp_metadata_generate_exif (orig_image_ID);
if (exif_data)
jpeg_setup_exif_for_save (exif_data, orig_image_ID);
#endif /* HAVE_EXIF */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment