Commit c200cbf3 authored by Paolo Bacchilega's avatar Paolo Bacchilega

preserve the exif data after a lossless rotation

read the exif data from the input buffer to make sure that they are
read correctly, instead of reading them from the output buffer after
the transformation.
parent 607d4353
......@@ -24,6 +24,7 @@
#include <config.h>
#include <gtk/gtk.h>
#include <gthumb.h>
#include <extensions/jpeg_utils/jpegtran.h>
#include "gth-edit-exiv2-page.h"
#include "gth-metadata-provider-exiv2.h"
#include "exiv2-utils.h"
......@@ -167,21 +168,19 @@ update_exif_dimensions (GFileInfo *info,
static void
exiv2_jpeg_tran_cb (void **out_buffer,
gsize *out_buffer_size,
GthTransform *transform)
exiv2_jpeg_tran_cb (JpegTranInfo *tran_info)
{
GFileInfo *info;
info = g_file_info_new ();
if (exiv2_read_metadata_from_buffer (*out_buffer, *out_buffer_size, info, NULL)) {
if (exiv2_read_metadata_from_buffer (tran_info->in_buffer, tran_info->in_buffer_size, info, NULL)) {
GthMetadata *metadata;
update_exif_dimensions (info, *transform);
update_exif_dimensions (info, tran_info->transformation);
metadata = g_object_new (GTH_TYPE_METADATA, "raw", "1", NULL);
g_file_info_set_attribute_object (info, "Exif::Image::Orientation", G_OBJECT (metadata));
exiv2_write_metadata_to_buffer (out_buffer, out_buffer_size, info, NULL, NULL);
exiv2_write_metadata_to_buffer (tran_info->out_buffer, tran_info->out_buffer_size, info, NULL, NULL);
g_object_unref (metadata);
}
......
......@@ -33,11 +33,10 @@ gthumb_extension_activate (void)
/**
* Called after successfully rotating a jpeg image
*
* @out_buffer (void **): pointer to file data
* @out_buffer_size (gsize *): pointer to file data size
* @tranform (GthTransform *): the transformation applied to the file
* @info (JpegTranInfo *): the transformation info as described in
* extensions/jpeg_utils/jpegtran.h
**/
gth_hook_register ("jpegtran-after", 3);
gth_hook_register ("jpegtran-after", 1);
gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (ir__gth_browser_construct_cb), NULL);
gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (ir__gth_browser_update_sensitivity_cb), NULL);
......
......@@ -222,7 +222,6 @@ jpegtran_internal (struct jpeg_decompress_struct *srcinfo,
/* Initialize destination compression parameters from source values */
jpeg_copy_critical_parameters (srcinfo, dstinfo);
/* Do not output a JFIF marker for EXIF thumbnails.
* This is not the optimal way to detect the difference
* between a thumbnail and a normal image, but it works
......@@ -230,13 +229,6 @@ jpegtran_internal (struct jpeg_decompress_struct *srcinfo,
if (option == JCOPYOPT_NONE)
dstinfo->write_JFIF_header = FALSE;
#if JPEG_LIB_VERSION < 80
/* Adjust the markers to create a standard EXIF file if an EXIF marker
* is present in the input. By default, libjpeg creates a JFIF file,
* which is incompatible with the EXIF standard. */
jcopy_markers_exif (srcinfo, dstinfo, option);
#endif
/* Adjust destination parameters if required by transform options;
* also find out which set of coefficient arrays will hold the output.
*/
......@@ -336,7 +328,14 @@ jpegtran (void *in_buffer,
jpeg_destroy_decompress (&srcinfo);
if (success) {
gth_hook_invoke ("jpegtran-after", out_buffer, out_buffer_size, &transformation);
JpegTranInfo info;
info.in_buffer = in_buffer;
info.in_buffer_size = in_buffer_size;
info.out_buffer = out_buffer;
info.out_buffer_size = out_buffer_size;
info.transformation = transformation;
gth_hook_invoke ("jpegtran-after", &info);
}
else {
g_free (*out_buffer);
......
......@@ -46,6 +46,15 @@ typedef enum {
} JpegMcuAction;
typedef struct {
void *in_buffer;
gsize in_buffer_size;
void **out_buffer;
gsize *out_buffer_size;
GthTransform transformation;
} JpegTranInfo;
gboolean jpegtran (void *in_buffer,
gsize in_buffer_size,
void **out_buffer,
......
......@@ -20,6 +20,8 @@
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
#include <config.h>
#ifdef HAVE_LIBJPEG
#include <jpeglib.h>
......
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