Commit e737bf77 authored by Michael Natterer's avatar Michael Natterer 😴

app: add gimp-babl.[ch] and move Babl specific code there

parent 16635e5f
......@@ -34,7 +34,7 @@
#include "config/gimpcoreconfig.h"
#include "gegl/gimp-gegl.h"
#include "gegl/gimp-babl.h"
#include "gegl/gimp-gegl-utils.h"
#include "gimp.h"
......
......@@ -31,7 +31,7 @@
#include "config/gimpdisplayconfig.h"
#include "gegl/gimp-gegl.h"
#include "gegl/gimp-babl.h"
#include "core/gimpcontainer.h"
#include "core/gimpdrawable.h"
......
......@@ -18,6 +18,8 @@ noinst_LIBRARIES = libappgegl.a
libappgegl_a_sources = \
gimp-gegl-enums.h \
gimp-gegl-types.h \
gimp-babl.c \
gimp-babl.h \
gimp-gegl.c \
gimp-gegl.h \
gimp-gegl-config-proxy.c \
......
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-babl.c
* Copyright (C) 2012 Michael Natterer <mitch@gimp.org>
*
* 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 <gegl.h>
#include "gimp-gegl-types.h"
#include "gimp-babl.h"
#include "gimp-intl.h"
void
gimp_babl_init (void)
{
babl_format_new ("name", "R' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("R'"),
NULL);
babl_format_new ("name", "G' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("G'"),
NULL);
babl_format_new ("name", "B' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("B'"),
NULL);
babl_format_new ("name", "A u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("A"),
NULL);
babl_format_new ("name", "A float",
babl_model ("R'G'B'A"),
babl_type ("float"),
babl_component ("A"),
NULL);
babl_format_new ("name", "A double",
babl_model ("R'G'B'A"),
babl_type ("double"),
babl_component ("A"),
NULL);
}
static const struct
{
const gchar *name;
const gchar *description;
}
babl_descriptions[] =
{
{ "R'G'B' u8", N_("RGB") },
{ "R'G'B'A u8", N_("RGB-alpha") },
{ "Y' u8", N_("Grayscale") },
{ "Y'A u8", N_("Grayscale-alpha") },
{ "R' u8", N_("Red component") },
{ "G' u8", N_("Green component") },
{ "B' u8", N_("Blue component") },
{ "A u8", N_("Alpha component") }
};
static GHashTable *babl_description_hash = NULL;
const gchar *
gimp_babl_get_description (const Babl *babl)
{
const gchar *description;
g_return_val_if_fail (babl != NULL, NULL);
if (G_UNLIKELY (! babl_description_hash))
{
gint i;
babl_description_hash = g_hash_table_new (g_str_hash,
g_str_equal);
for (i = 0; i < G_N_ELEMENTS (babl_descriptions); i++)
g_hash_table_insert (babl_description_hash,
(gpointer) babl_descriptions[i].name,
gettext (babl_descriptions[i].description));
}
if (babl_format_is_palette (babl))
{
if (babl_format_has_alpha (babl))
return _("Indexed-alpha");
else
return _("Indexed");
}
description = g_hash_table_lookup (babl_description_hash,
babl_get_name (babl));
if (description)
return description;
return g_strconcat ("ERROR: unknown Babl format ",
babl_get_name (babl), NULL);
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* gimp-babl.h
* Copyright (C) 2012 Michael Natterer <mitch@gimp.org>
*
* 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_BABL_H__
#define __GIMP_BABL_H__
void gimp_babl_init (void);
const gchar * gimp_babl_get_description (const Babl *babl);
#endif /* __GIMP_BABL_H__ */
......@@ -30,6 +30,7 @@
#include "core/gimp.h"
#include "gimp-babl.h"
#include "gimp-gegl.h"
#include "gimpoperationborder.h"
......@@ -80,8 +81,6 @@
#include "gimpoperationreplacemode.h"
#include "gimpoperationantierasemode.h"
#include "gimp-intl.h"
static void gimp_gegl_notify_tile_cache_size (GimpBaseConfig *config);
......@@ -113,38 +112,7 @@ gimp_gegl_init (Gimp *gimp)
G_CALLBACK (gimp_gegl_notify_tile_cache_size),
NULL);
babl_format_new ("name", "R' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("R'"),
NULL);
babl_format_new ("name", "G' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("G'"),
NULL);
babl_format_new ("name", "B' u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("B'"),
NULL);
babl_format_new ("name", "A u8",
babl_model ("R'G'B'A"),
babl_type ("u8"),
babl_component ("A"),
NULL);
babl_format_new ("name", "A float",
babl_model ("R'G'B'A"),
babl_type ("float"),
babl_component ("A"),
NULL);
babl_format_new ("name", "A double",
babl_model ("R'G'B'A"),
babl_type ("double"),
babl_component ("A"),
NULL);
gimp_babl_init ();
g_type_class_ref (GIMP_TYPE_OPERATION_BORDER);
g_type_class_ref (GIMP_TYPE_OPERATION_CAGE_COEF_CALC);
......@@ -195,63 +163,6 @@ gimp_gegl_init (Gimp *gimp)
g_type_class_ref (GIMP_TYPE_OPERATION_ANTI_ERASE_MODE);
}
static const struct
{
const gchar *name;
const gchar *description;
}
babl_descriptions[] =
{
{ "R'G'B' u8", N_("RGB") },
{ "R'G'B'A u8", N_("RGB-alpha") },
{ "Y' u8", N_("Grayscale") },
{ "Y'A u8", N_("Grayscale-alpha") },
{ "R' u8", N_("Red component") },
{ "G' u8", N_("Green component") },
{ "B' u8", N_("Blue component") },
{ "A u8", N_("Alpha component") }
};
static GHashTable *babl_description_hash = NULL;
const gchar *
gimp_babl_get_description (const Babl *babl)
{
const gchar *description;
g_return_val_if_fail (babl != NULL, NULL);
if (G_UNLIKELY (! babl_description_hash))
{
gint i;
babl_description_hash = g_hash_table_new (g_str_hash,
g_str_equal);
for (i = 0; i < G_N_ELEMENTS (babl_descriptions); i++)
g_hash_table_insert (babl_description_hash,
(gpointer) babl_descriptions[i].name,
gettext (babl_descriptions[i].description));
}
if (babl_format_is_palette (babl))
{
if (babl_format_has_alpha (babl))
return _("Indexed-alpha");
else
return _("Indexed");
}
description = g_hash_table_lookup (babl_description_hash,
babl_get_name (babl));
if (description)
return description;
return g_strconcat ("ERROR: unknown Babl format ",
babl_get_name (babl), NULL);
}
static void
gimp_gegl_notify_tile_cache_size (GimpBaseConfig *config)
{
......
......@@ -22,9 +22,7 @@
#define __GIMP_GEGL_H__
void gimp_gegl_init (Gimp *gimp);
const gchar * gimp_babl_get_description (const Babl *babl);
void gimp_gegl_init (Gimp *gimp);
#endif /* __GIMP_GEGL_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