app: add gimp_image_get_profile() which returns a cmsHPROFILE
This commit is contained in:
parent
a83851eb37
commit
89e0c04d13
4 changed files with 172 additions and 37 deletions
129
app/core/gimpimage-profile.c
Normal file
129
app/core/gimpimage-profile.c
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <glib.h> /* lcms.h uses the "inline" keyword */
|
||||
|
||||
#include <lcms2.h>
|
||||
|
||||
#include <cairo.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gegl.h>
|
||||
|
||||
#include "libgimpconfig/gimpconfig.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "config/gimpcoreconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "gimperror.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-profile.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
const GimpParasite *
|
||||
gimp_image_get_icc_profile (GimpImage *image)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
return gimp_image_parasite_find (image, GIMP_ICC_PROFILE_PARASITE_NAME);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_set_icc_profile (GimpImage *image,
|
||||
const GimpParasite *icc_profile)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
if (icc_profile)
|
||||
{
|
||||
g_return_if_fail (strcmp (gimp_parasite_name (icc_profile),
|
||||
GIMP_ICC_PROFILE_PARASITE_NAME) == 0);
|
||||
g_return_if_fail (gimp_parasite_flags (icc_profile) ==
|
||||
(GIMP_PARASITE_PERSISTENT |
|
||||
GIMP_PARASITE_UNDOABLE));
|
||||
|
||||
gimp_image_parasite_attach (image, icc_profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
GimpColorProfile
|
||||
gimp_image_get_profile (GimpImage *image,
|
||||
guint8 *md5_digest,
|
||||
GError **error)
|
||||
{
|
||||
GimpColorConfig *config;
|
||||
const GimpParasite *parasite;
|
||||
GimpColorProfile *profile = NULL;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
|
||||
|
||||
config = image->gimp->config->color_management;
|
||||
|
||||
parasite = gimp_image_get_icc_profile (image);
|
||||
|
||||
if (parasite)
|
||||
{
|
||||
profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
|
||||
gimp_parasite_data_size (parasite),
|
||||
md5_digest, error);
|
||||
|
||||
if (! profile)
|
||||
g_prefix_error (error,
|
||||
_("Error parsing data attached as 'icc-profile': "));
|
||||
|
||||
if (profile && ! gimp_lcms_profile_is_rgb (profile))
|
||||
{
|
||||
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("Color profile attached as 'icc-profile' is "
|
||||
"not for RGB color space"));
|
||||
cmsCloseProfile (profile);
|
||||
profile = NULL;
|
||||
}
|
||||
}
|
||||
else if (config->rgb_profile)
|
||||
{
|
||||
profile = gimp_lcms_profile_open_from_file (config->rgb_profile,
|
||||
md5_digest, error);
|
||||
|
||||
if (profile && ! gimp_lcms_profile_is_rgb (profile))
|
||||
{
|
||||
g_set_error (error, GIMP_ERROR, GIMP_FAILED,
|
||||
_("Color profile '%s' is not for RGB color space"),
|
||||
gimp_filename_to_utf8 (config->rgb_profile));
|
||||
cmsCloseProfile (profile);
|
||||
profile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return profile;
|
||||
}
|
||||
34
app/core/gimpimage-profile.h
Normal file
34
app/core/gimpimage-profile.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/* GIMP - The GNU 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_IMAGE_PROFILE_H__
|
||||
#define __GIMP_IMAGE_PROFILE_H__
|
||||
|
||||
|
||||
#define GIMP_ICC_PROFILE_PARASITE_NAME "icc-profile"
|
||||
|
||||
|
||||
const GimpParasite * gimp_image_get_icc_profile (GimpImage *image);
|
||||
void gimp_image_set_icc_profile (GimpImage *image,
|
||||
const GimpParasite *icc_profile);
|
||||
|
||||
GimpColorProfile gimp_image_get_profile (GimpImage *image,
|
||||
guint8 *md5_digest,
|
||||
GError **error);
|
||||
|
||||
|
||||
#endif /* __GIMP_IMAGE_PROFILE_H__ */
|
||||
|
|
@ -36,9 +36,6 @@
|
|||
|
||||
#include "widgets-types.h"
|
||||
|
||||
#include "config/gimpcoreconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-profile.h"
|
||||
|
||||
|
|
@ -109,43 +106,17 @@ gimp_image_profile_view_update (GimpImageParasiteView *view)
|
|||
{
|
||||
GimpImageProfileView *profile_view = GIMP_IMAGE_PROFILE_VIEW (view);
|
||||
GimpImage *image;
|
||||
GimpColorConfig *config;
|
||||
const GimpParasite *parasite;
|
||||
GimpColorProfile *profile = NULL;
|
||||
GError *error = NULL;
|
||||
GimpColorProfile *profile;
|
||||
GError *error = NULL;
|
||||
|
||||
image = gimp_image_parasite_view_get_image (view);
|
||||
parasite = gimp_image_parasite_view_get_parasite (view);
|
||||
image = gimp_image_parasite_view_get_image (view);
|
||||
|
||||
config = image->gimp->config->color_management;
|
||||
profile = gimp_image_get_profile (image, NULL, &error);
|
||||
|
||||
if (parasite)
|
||||
if (! profile && error)
|
||||
{
|
||||
profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
|
||||
gimp_parasite_data_size (parasite),
|
||||
NULL, &error);
|
||||
if (! profile)
|
||||
{
|
||||
g_message (_("Error parsing 'icc-profile': %s"), error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
else if (config->rgb_profile)
|
||||
{
|
||||
profile = gimp_lcms_profile_open_from_file (config->rgb_profile,
|
||||
NULL, &error);
|
||||
if (! profile)
|
||||
{
|
||||
g_message ("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
||||
if (profile && ! gimp_lcms_profile_is_rgb (profile))
|
||||
{
|
||||
g_message (_("Color profile is not for RGB color space (skipping)"));
|
||||
cmsCloseProfile (profile);
|
||||
profile = NULL;
|
||||
g_message ("%s", error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
if (! profile)
|
||||
|
|
|
|||
|
|
@ -128,8 +128,8 @@ app/core/gimp-gradients.c
|
|||
app/core/gimpgrid.c
|
||||
app/core/gimpgrouplayer.c
|
||||
app/core/gimp-gui.c
|
||||
app/core/gimpimage-arrange.c
|
||||
app/core/gimpimage.c
|
||||
app/core/gimpimage-arrange.c
|
||||
app/core/gimpimage-colormap.c
|
||||
app/core/gimpimage-convert-precision.c
|
||||
app/core/gimpimage-convert-type.c
|
||||
|
|
@ -140,6 +140,7 @@ app/core/gimpimage-guides.c
|
|||
app/core/gimpimage-item-list.c
|
||||
app/core/gimpimage-merge.c
|
||||
app/core/gimpimage-new.c
|
||||
app/core/gimpimage-profile.c
|
||||
app/core/gimpimage-quick-mask.c
|
||||
app/core/gimpimage-resize.c
|
||||
app/core/gimpimage-sample-points.c
|
||||
|
|
|
|||
Loading…
Reference in a new issue