app: add gimp_babl_format_get_color_profile()
and remove the code duplication added a few commits before.
This commit is contained in:
@ -347,68 +347,12 @@ gimp_buffer_color_managed_get_icc_profile (GimpColorManaged *managed,
|
||||
static GimpColorProfile *
|
||||
gimp_buffer_color_managed_get_color_profile (GimpColorManaged *managed)
|
||||
{
|
||||
GimpBuffer *buffer = GIMP_BUFFER (managed);
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *gray_profile = NULL;
|
||||
static GimpColorProfile *linear_gray_profile = NULL;
|
||||
const Babl *format;
|
||||
GimpBuffer *buffer = GIMP_BUFFER (managed);
|
||||
|
||||
if (buffer->color_profile)
|
||||
return buffer->color_profile;
|
||||
|
||||
format = gimp_buffer_get_format (buffer);
|
||||
|
||||
if (gimp_babl_format_get_base_type (format) == GIMP_GRAY)
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_gray_profile)
|
||||
{
|
||||
linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
|
||||
(gpointer) &linear_gray_profile);
|
||||
}
|
||||
|
||||
return linear_gray_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! gray_profile)
|
||||
{
|
||||
gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
|
||||
g_object_add_weak_pointer (G_OBJECT (gray_profile),
|
||||
(gpointer) &gray_profile);
|
||||
}
|
||||
|
||||
return gray_profile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_rgb_profile)
|
||||
{
|
||||
linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
|
||||
(gpointer) &linear_rgb_profile);
|
||||
}
|
||||
|
||||
return linear_rgb_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_rgb_srgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (srgb_profile),
|
||||
(gpointer) &srgb_profile);
|
||||
}
|
||||
|
||||
return srgb_profile;
|
||||
}
|
||||
}
|
||||
return gimp_babl_format_get_color_profile (gimp_buffer_get_format (buffer));
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@ -307,66 +307,13 @@ gimp_image_set_color_profile (GimpImage *image,
|
||||
GimpColorProfile *
|
||||
gimp_image_get_builtin_color_profile (GimpImage *image)
|
||||
{
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *gray_profile = NULL;
|
||||
static GimpColorProfile *linear_gray_profile = NULL;
|
||||
const Babl *format;
|
||||
const Babl *format;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
format = gimp_image_get_layer_format (image, FALSE);
|
||||
|
||||
if (gimp_image_get_base_type (image) == GIMP_GRAY)
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_gray_profile)
|
||||
{
|
||||
linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
|
||||
(gpointer) &linear_gray_profile);
|
||||
}
|
||||
|
||||
return linear_gray_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! gray_profile)
|
||||
{
|
||||
gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
|
||||
g_object_add_weak_pointer (G_OBJECT (gray_profile),
|
||||
(gpointer) &gray_profile);
|
||||
}
|
||||
|
||||
return gray_profile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_rgb_profile)
|
||||
{
|
||||
linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
|
||||
(gpointer) &linear_rgb_profile);
|
||||
}
|
||||
|
||||
return linear_rgb_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_rgb_srgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (srgb_profile),
|
||||
(gpointer) &srgb_profile);
|
||||
}
|
||||
|
||||
return srgb_profile;
|
||||
}
|
||||
}
|
||||
return gimp_babl_format_get_color_profile (format);
|
||||
}
|
||||
|
||||
gboolean
|
||||
|
||||
@ -20,8 +20,12 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <cairo.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#include <gegl.h>
|
||||
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
|
||||
#include "gimp-gegl-types.h"
|
||||
|
||||
#include "gimp-babl.h"
|
||||
@ -395,6 +399,68 @@ gimp_babl_format_get_description (const Babl *babl)
|
||||
babl_get_name (babl), NULL);
|
||||
}
|
||||
|
||||
GimpColorProfile *
|
||||
gimp_babl_format_get_color_profile (const Babl *format)
|
||||
{
|
||||
static GimpColorProfile *srgb_profile = NULL;
|
||||
static GimpColorProfile *linear_rgb_profile = NULL;
|
||||
static GimpColorProfile *gray_profile = NULL;
|
||||
static GimpColorProfile *linear_gray_profile = NULL;
|
||||
|
||||
g_return_val_if_fail (format != NULL, NULL);
|
||||
|
||||
if (gimp_babl_format_get_base_type (format) == GIMP_GRAY)
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_gray_profile)
|
||||
{
|
||||
linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
|
||||
(gpointer) &linear_gray_profile);
|
||||
}
|
||||
|
||||
return linear_gray_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! gray_profile)
|
||||
{
|
||||
gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
|
||||
g_object_add_weak_pointer (G_OBJECT (gray_profile),
|
||||
(gpointer) &gray_profile);
|
||||
}
|
||||
|
||||
return gray_profile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gimp_babl_format_get_linear (format))
|
||||
{
|
||||
if (! linear_rgb_profile)
|
||||
{
|
||||
linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
|
||||
g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
|
||||
(gpointer) &linear_rgb_profile);
|
||||
}
|
||||
|
||||
return linear_rgb_profile;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! srgb_profile)
|
||||
{
|
||||
srgb_profile = gimp_color_profile_new_rgb_srgb ();
|
||||
g_object_add_weak_pointer (G_OBJECT (srgb_profile),
|
||||
(gpointer) &srgb_profile);
|
||||
}
|
||||
|
||||
return srgb_profile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GimpImageBaseType
|
||||
gimp_babl_format_get_base_type (const Babl *format)
|
||||
{
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
void gimp_babl_init (void);
|
||||
|
||||
const gchar * gimp_babl_format_get_description (const Babl *format);
|
||||
GimpColorProfile * gimp_babl_format_get_color_profile (const Babl *format);
|
||||
|
||||
GimpImageBaseType gimp_babl_format_get_base_type (const Babl *format);
|
||||
GimpComponentType gimp_babl_format_get_component_type (const Babl *format);
|
||||
|
||||
Reference in New Issue
Block a user