summaryrefslogtreecommitdiff
path: root/extensions
diff options
context:
space:
mode:
authorØyvind Kolås <pippin@gimp.org>2018-11-12 23:35:31 +0100
committerØyvind Kolås <pippin@gimp.org>2018-11-24 03:57:24 +0100
commit843e091485f7716b86fd26d546b99f49dddcad08 (patch)
treeeed5a0c00c1147583043f66edaf09bdaf8bb52ed /extensions
parent0f376418ff187245275289c74128e0dd9a5f208b (diff)
babl: implement CMYK color model in reference and base
This commit adds support to the reference fishes of babl to deal with CMYK based pixel format encodings, backed by babl spaces with ICC CMYK ICC profiles.
Diffstat (limited to 'extensions')
-rw-r--r--extensions/Makefile.am1
-rw-r--r--extensions/naive-CMYK.c243
2 files changed, 6 insertions, 238 deletions
diff --git a/extensions/Makefile.am b/extensions/Makefile.am
index a066e8d..50e2a8e 100644
--- a/extensions/Makefile.am
+++ b/extensions/Makefile.am
@@ -54,6 +54,7 @@ gggl_table_la_SOURCES = gggl-table.c
gggl_la_SOURCES = gggl.c
gimp_8bit_la_SOURCES = gimp-8bit.c
grey_la_SOURCES = grey.c
+CMYK_la_SOURCES = CMYK.c
naive_CMYK_la_SOURCES = naive-CMYK.c
HCY_la_SOURCES = HCY.c
HSL_la_SOURCES = HSL.c
diff --git a/extensions/naive-CMYK.c b/extensions/naive-CMYK.c
index 3b7a70c..a8a874a 100644
--- a/extensions/naive-CMYK.c
+++ b/extensions/naive-CMYK.c
@@ -1,5 +1,5 @@
/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
+ * Copyright (C) 2005, 2018 Øyvind Kolås.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -14,6 +14,9 @@
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, see
* <https://www.gnu.org/licenses/>.
+ *
+ * this is an interim file, to keep babl from complaining about double
+ * registration of cmyk formats.
*/
#include "config.h"
@@ -23,248 +26,12 @@
#include "babl.h"
#include "base/util.h"
-
-static void rgba_to_cmyk (const Babl *conversion,char *src,
- char *dst,
- long n);
-
-static void cmyk_to_rgba (const Babl *conversion,char *src,
- char *dst,
- long n);
-
-static void rgba_to_cmy (const Babl *conversion,char *src,
- char *dst,
- long n);
-
-static void cmy_to_rgba (const Babl *conversion,char *src,
- char *dst,
- long n);
-
int init (void);
int
init (void)
{
- babl_component_new ("cyan", NULL);
- babl_component_new ("yellow", NULL);
- babl_component_new ("magenta", NULL);
- babl_component_new ("key", NULL);
-
- babl_model_new (
- "name", "CMYK",
- babl_component ("cyan"),
- babl_component ("magenta"),
- babl_component ("yellow"),
- babl_component ("key"),
- NULL
- );
- babl_model_new (
- "name", "CMY",
- babl_component ("cyan"),
- babl_component ("magenta"),
- babl_component ("yellow"),
- NULL
- );
-
- babl_conversion_new (
- babl_model ("RGBA"),
- babl_model ("CMYK"),
- "linear", rgba_to_cmyk,
- NULL
- );
- babl_conversion_new (
- babl_model ("CMYK"),
- babl_model ("RGBA"),
- "linear", cmyk_to_rgba,
- NULL
- );
- babl_conversion_new (
- babl_model ("RGBA"),
- babl_model ("CMY"),
- "linear", rgba_to_cmy,
- NULL
- );
- babl_conversion_new (
- babl_model ("CMY"),
- babl_model ("RGBA"),
- "linear", cmy_to_rgba,
- NULL
- );
-
- babl_format_new (
- "name", "CMYK float",
- babl_model ("CMYK"),
- babl_type ("float"),
- babl_component ("cyan"),
- babl_component ("magenta"),
- babl_component ("yellow"),
- babl_component ("key"),
- NULL
- );
- babl_format_new (
- "name", "CMY float",
- babl_model ("CMY"),
- babl_type ("float"),
- babl_component ("cyan"),
- babl_component ("magenta"),
- babl_component ("yellow"),
- NULL
- );
-
- babl_format_new (
- "name", "CMYK u8",
- babl_model ("CMYK"),
- babl_type ("u8"),
- babl_component ("cyan"),
- babl_component ("magenta"),
- babl_component ("yellow"),
- babl_component ("key"),
- NULL
- );
-
+ /* do nothing, drop this whole file after a couple of releases */
return 0;
}
-
-static void
-rgba_to_cmyk (const Babl *conversion,char *src,
- char *dst,
- long n)
-{
- while (n--)
- {
- double red = linear_to_gamma_2_2 (((double *) src)[0]);
- double green = linear_to_gamma_2_2 (((double *) src)[1]);
- double blue = linear_to_gamma_2_2 (((double *) src)[2]);
-
- double cyan, magenta, yellow, key;
-
- double pullout = 1.0;
-
- cyan = 1.0 - red;
- magenta = 1.0 - green;
- yellow = 1.0 - blue;
-
- key = 1.0;
- if (cyan < key) key = cyan;
- if (magenta < key) key = magenta;
- if (yellow < key) key = yellow;
-
- key *= pullout;
-
- if (key < 1.0)
- {
- cyan = (cyan - key) / (1.0 - key);
- magenta = (magenta - key) / (1.0 - key);
- yellow = (yellow - key) / (1.0 - key);
- }
- else
- {
- cyan = 0.0;
- magenta = 0.0;
- yellow = 0.0;
- }
-
- ((double *) dst)[0] = cyan;
- ((double *) dst)[1] = magenta;
- ((double *) dst)[2] = yellow;
- ((double *) dst)[3] = key;
-
- src += 4 * sizeof (double);
- dst += 4 * sizeof (double);
- }
-}
-
-static void
-cmyk_to_rgba (const Babl *conversion,char *src,
- char *dst,
- long n)
-{
- while (n--)
- {
- double cyan = ((double *) src)[0];
- double magenta = ((double *) src)[1];
- double yellow = ((double *) src)[2];
- double key = ((double *) src)[3];
-
- double red, green, blue;
-
- if (key < 1.0)
- {
- cyan = cyan * (1.0 - key) + key;
- magenta = magenta * (1.0 - key) + key;
- yellow = yellow * (1.0 - key) + key;
- }
- else
- {
- cyan = magenta = yellow = 1.0;
- }
-
- red = 1.0 - cyan;
- green = 1.0 - magenta;
- blue = 1.0 - yellow;
-
- ((double *) dst)[0] = gamma_2_2_to_linear (red);
- ((double *) dst)[1] = gamma_2_2_to_linear (green);
- ((double *) dst)[2] = gamma_2_2_to_linear (blue);
-
- ((double *) dst)[3] = 1.0;
-
- src += 4 * sizeof (double);
- dst += 4 * sizeof (double);
- }
-}
-
-static void
-rgba_to_cmy (const Babl *conversion,char *src,
- char *dst,
- long n)
-{
- while (n--)
- {
- double red = linear_to_gamma_2_2 (((double *) src)[0]);
- double green = linear_to_gamma_2_2 (((double *) src)[1]);
- double blue = linear_to_gamma_2_2 (((double *) src)[2]);
-
- double cyan, magenta, yellow;
-
- cyan = 1.0 - red;
- magenta = 1.0 - green;
- yellow = 1.0 - blue;
-
- ((double *) dst)[0] = cyan;
- ((double *) dst)[1] = magenta;
- ((double *) dst)[2] = yellow;
-
- src += 4 * sizeof (double);
- dst += 3 * sizeof (double);
- }
-}
-
-static void
-cmy_to_rgba (const Babl *conversion,char *src,
- char *dst,
- long n)
-{
- while (n--)
- {
- double cyan = ((double *) src)[0];
- double magenta = ((double *) src)[1];
- double yellow = ((double *) src)[2];
-
- double red, green, blue;
-
- red = 1.0 - cyan;
- green = 1.0 - magenta;
- blue = 1.0 - yellow;
-
- ((double *) dst)[0] = gamma_2_2_to_linear (red);
- ((double *) dst)[1] = gamma_2_2_to_linear (green);
- ((double *) dst)[2] = gamma_2_2_to_linear (blue);
-
- ((double *) dst)[3] = 1.0;
-
- src += 3 * sizeof (double);
- dst += 4 * sizeof (double);
- }
-}