app: consolidate all metadata syncing code into gimpimage-metadata.c

Add gimp_image_metadata_update_pixel_size(), _bits_per_sample(),
_resolution() and use them from gimp_image_set_metadata() and from
various places in gimpimage.c which had identical copies of the same
code.

Also add gimp_image_metadata_update_colorspace() which syncs the color
space stored in the image's metadata with the color space of the
image's actual color profile. Call the function from the right places.

The body of gimp_image_metadata_update_colorspace() is currently
disabled because the syncing of color space information is
controversial, see issue ##3532 and issue #301.

(cherry picked from commit b9829eddfe)
This commit is contained in:
Michael Natterer
2019-06-20 16:13:19 +02:00
parent 11dfa49b44
commit da33bb5107
3 changed files with 134 additions and 91 deletions

View File

@ -17,14 +17,17 @@
#include "config.h"
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpcolor/gimpcolor.h"
#include "core-types.h"
#include "gimpimage.h"
#include "gimpimage-color-profile.h"
#include "gimpimage-metadata.h"
#include "gimpimage-private.h"
#include "gimpimage-undo-push.h"
@ -65,38 +68,121 @@ gimp_image_set_metadata (GimpImage *image,
if (private->metadata)
{
gdouble xres, yres;
gimp_metadata_set_pixel_size (metadata,
gimp_image_get_width (image),
gimp_image_get_height (image));
switch (gimp_image_get_component_type (image))
{
case GIMP_COMPONENT_TYPE_U8:
gimp_metadata_set_bits_per_sample (metadata, 8);
break;
case GIMP_COMPONENT_TYPE_U16:
case GIMP_COMPONENT_TYPE_HALF:
gimp_metadata_set_bits_per_sample (metadata, 16);
break;
case GIMP_COMPONENT_TYPE_U32:
case GIMP_COMPONENT_TYPE_FLOAT:
gimp_metadata_set_bits_per_sample (metadata, 32);
break;
case GIMP_COMPONENT_TYPE_DOUBLE:
gimp_metadata_set_bits_per_sample (metadata, 64);
break;
}
gimp_image_get_resolution (image, &xres, &yres);
gimp_metadata_set_resolution (metadata, xres, yres,
gimp_image_get_unit (image));
gimp_image_metadata_update_pixel_size (image);
gimp_image_metadata_update_bits_per_sample (image);
gimp_image_metadata_update_resolution (image);
gimp_image_metadata_update_colorspace (image);
}
g_object_notify (G_OBJECT (image), "metadata");
}
}
void
gimp_image_metadata_update_pixel_size (GimpImage *image)
{
GimpMetadata *metadata;
g_return_if_fail (GIMP_IS_IMAGE (image));
metadata = gimp_image_get_metadata (image);
if (metadata)
{
gimp_metadata_set_pixel_size (metadata,
gimp_image_get_width (image),
gimp_image_get_height (image));
}
}
void
gimp_image_metadata_update_bits_per_sample (GimpImage *image)
{
GimpMetadata *metadata;
g_return_if_fail (GIMP_IS_IMAGE (image));
metadata = gimp_image_get_metadata (image);
if (metadata)
{
switch (gimp_image_get_component_type (image))
{
case GIMP_COMPONENT_TYPE_U8:
gimp_metadata_set_bits_per_sample (metadata, 8);
break;
case GIMP_COMPONENT_TYPE_U16:
case GIMP_COMPONENT_TYPE_HALF:
gimp_metadata_set_bits_per_sample (metadata, 16);
break;
case GIMP_COMPONENT_TYPE_U32:
case GIMP_COMPONENT_TYPE_FLOAT:
gimp_metadata_set_bits_per_sample (metadata, 32);
break;
case GIMP_COMPONENT_TYPE_DOUBLE:
gimp_metadata_set_bits_per_sample (metadata, 64);
break;
}
}
}
void
gimp_image_metadata_update_resolution (GimpImage *image)
{
GimpMetadata *metadata;
g_return_if_fail (GIMP_IS_IMAGE (image));
metadata = gimp_image_get_metadata (image);
if (metadata)
{
gdouble xres, yres;
gimp_image_get_resolution (image, &xres, &yres);
gimp_metadata_set_resolution (metadata, xres, yres,
gimp_image_get_unit (image));
}
}
void
gimp_image_metadata_update_colorspace (GimpImage *image)
{
GimpMetadata *metadata;
g_return_if_fail (GIMP_IS_IMAGE (image));
metadata = gimp_image_get_metadata (image);
if (metadata)
{
/* This seems to be controversial, see the discussions in issue
* #3532 and issue #301. Enable the code below to test the
* proposed syncing of color profile and DCF info.
*/
#if 0
GimpColorProfile *profile = gimp_image_get_color_profile (image);
GimpMetadataColorspace space = GIMP_METADATA_COLORSPACE_UNSPECIFIED;
if (profile)
{
static GimpColorProfile *adobe = NULL;
if (! adobe)
adobe = gimp_color_profile_new_rgb_adobe ();
if (gimp_color_profile_is_equal (profile, adobe))
space = GIMP_METADATA_COLORSPACE_ADOBERGB;
}
else
{
space = GIMP_METADATA_COLORSPACE_SRGB;
}
gimp_metadata_set_colorspace (metadata, space);
#endif
}
}

View File

@ -19,10 +19,15 @@
#define __GIMP_IMAGE_METADATA_H__
GimpMetadata * gimp_image_get_metadata (GimpImage *image);
void gimp_image_set_metadata (GimpImage *image,
GimpMetadata *metadata,
gboolean push_undo);
GimpMetadata * gimp_image_get_metadata (GimpImage *image);
void gimp_image_set_metadata (GimpImage *image,
GimpMetadata *metadata,
gboolean push_undo);
void gimp_image_metadata_update_pixel_size (GimpImage *image);
void gimp_image_metadata_update_bits_per_sample (GimpImage *image);
void gimp_image_metadata_update_resolution (GimpImage *image);
void gimp_image_metadata_update_colorspace (GimpImage *image);
#endif /* __GIMP_IMAGE_METADATA_H__ */

View File

@ -1207,10 +1207,9 @@ gimp_image_get_size (GimpViewable *viewable,
static void
gimp_image_size_changed (GimpViewable *viewable)
{
GimpImage *image = GIMP_IMAGE (viewable);
GimpMetadata *metadata;
GList *all_items;
GList *list;
GimpImage *image = GIMP_IMAGE (viewable);
GList *all_items;
GList *list;
if (GIMP_VIEWABLE_CLASS (parent_class)->size_changed)
GIMP_VIEWABLE_CLASS (parent_class)->size_changed (viewable);
@ -1235,11 +1234,7 @@ gimp_image_size_changed (GimpViewable *viewable)
gimp_viewable_size_changed (GIMP_VIEWABLE (gimp_image_get_mask (image)));
metadata = gimp_image_get_metadata (image);
if (metadata)
gimp_metadata_set_pixel_size (metadata,
gimp_image_get_width (image),
gimp_image_get_height (image));
gimp_image_metadata_update_pixel_size (image);
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
}
@ -1267,32 +1262,7 @@ gimp_image_real_mode_changed (GimpImage *image)
static void
gimp_image_real_precision_changed (GimpImage *image)
{
GimpMetadata *metadata;
metadata = gimp_image_get_metadata (image);
if (metadata)
{
switch (gimp_image_get_component_type (image))
{
case GIMP_COMPONENT_TYPE_U8:
gimp_metadata_set_bits_per_sample (metadata, 8);
break;
case GIMP_COMPONENT_TYPE_U16:
case GIMP_COMPONENT_TYPE_HALF:
gimp_metadata_set_bits_per_sample (metadata, 16);
break;
case GIMP_COMPONENT_TYPE_U32:
case GIMP_COMPONENT_TYPE_FLOAT:
gimp_metadata_set_bits_per_sample (metadata, 32);
break;
case GIMP_COMPONENT_TYPE_DOUBLE:
gimp_metadata_set_bits_per_sample (metadata, 64);
break;
}
}
gimp_image_metadata_update_bits_per_sample (image);
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
}
@ -1300,17 +1270,7 @@ gimp_image_real_precision_changed (GimpImage *image)
static void
gimp_image_real_resolution_changed (GimpImage *image)
{
GimpMetadata *metadata;
metadata = gimp_image_get_metadata (image);
if (metadata)
{
gdouble xres, yres;
gimp_image_get_resolution (image, &xres, &yres);
gimp_metadata_set_resolution (metadata, xres, yres,
gimp_image_get_unit (image));
}
gimp_image_metadata_update_resolution (image);
}
static void
@ -1330,17 +1290,7 @@ gimp_image_real_size_changed_detailed (GimpImage *image,
static void
gimp_image_real_unit_changed (GimpImage *image)
{
GimpMetadata *metadata;
metadata = gimp_image_get_metadata (image);
if (metadata)
{
gdouble xres, yres;
gimp_image_get_resolution (image, &xres, &yres);
gimp_metadata_set_resolution (metadata, xres, yres,
gimp_image_get_unit (image));
}
gimp_image_metadata_update_resolution (image);
}
static void
@ -1403,6 +1353,8 @@ gimp_image_color_managed_profile_changed (GimpColorManaged *managed)
GimpImage *image = GIMP_IMAGE (managed);
GimpItemStack *layers = GIMP_ITEM_STACK (gimp_image_get_layers (image));
gimp_image_metadata_update_colorspace (image);
gimp_projectable_structure_changed (GIMP_PROJECTABLE (image));
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (image));
gimp_item_stack_profile_changed (layers);