[babl] babl: abstract space duplicate detection
- From: Øyvind Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] babl: abstract space duplicate detection
- Date: Sun, 3 Sep 2017 14:03:31 +0000 (UTC)
commit 633e2dfceb0bd8dae135058eead337395167c55a
Author: Øyvind Kolås <pippin gimp org>
Date: Sun Sep 3 16:03:13 2017 +0200
babl: abstract space duplicate detection
babl/babl-icc.c | 45 +++++++++++++++++----------------------------
babl/babl-internal.h | 8 ++++++++
babl/babl-space.c | 31 +++++++++++++++++++++++++++++++
babl/babl.h | 4 +---
4 files changed, 57 insertions(+), 31 deletions(-)
---
diff --git a/babl/babl-icc.c b/babl/babl-icc.c
index 3fa24e9..2682fcd 100644
--- a/babl/babl-icc.c
+++ b/babl/babl-icc.c
@@ -635,6 +635,7 @@ babl_space_from_icc (const char *icc_data,
const char *int_err;
char *descr = NULL;
char *copyright = NULL;
+ Babl *ret = NULL;
sign_t profile_class, color_space;
@@ -748,25 +749,16 @@ babl_space_from_icc (const char *icc_data,
wY = icc_read (s15f16, offset + 8 + 4);
wZ = icc_read (s15f16, offset + 8 + 4 * 2);
- if (trc_red == babl_trc ("sRGB") &&
- trc_green == babl_trc ("sRGB") &&
- trc_blue == babl_trc ("sRGB") &&
- fabs(rx - 0.436042) < 0.001 &&
- fabs(ry - 0.222492) < 0.001 &&
- fabs(rz - 0.013916) < 0.001 &&
- fabs(gx - 0.385122) < 0.001 &&
- fabs(gy - 0.716915) < 0.001 &&
- fabs(gz - 0.097063) < 0.001 &&
- fabs(bx - 0.143053) < 0.001 &&
- fabs(by - 0.060609) < 0.001 &&
- fabs(bz - 0.713939) < 0.001)
+ ret = (void*)babl_space_match_trc_matrix (trc_red, trc_green, trc_blue,
+ rx, ry, rz, gx, gy, gz, bx, by, bz);
+ if (ret)
{
babl_free (state);
- return babl_space ("sRGB");
+ return ret;
}
{
- Babl *ret = (void*)babl_space_from_rgbxyz_matrix (NULL,
+ ret = (void*)babl_space_from_rgbxyz_matrix (NULL,
wX, wY, wZ,
rx, gx, bx,
ry, gy, by,
@@ -792,7 +784,7 @@ babl_space_from_icc (const char *icc_data,
if (phosporant != 0)
{
- *error = "unhandled phosporants, please report bug";
+ *error = "unhandled phosporants, please report bug against babl with profile";
return NULL;
}
if (channels != 3)
@@ -815,19 +807,16 @@ babl_space_from_icc (const char *icc_data,
double wZ = icc_read (s15f16, offset + 8 + 4 * 2);
babl_free (state);
- {
- Babl *ret = (void*) babl_space_from_chromaticities (NULL,
- wX / (wX + wY + wZ),
- wY / (wX + wY + wZ),
- red_x, red_y,
- green_x, green_y,
- blue_x, blue_y,
- trc_red, trc_green, trc_blue);
- ret->space.description = descr;
- ret->space.copyright = copyright;
- return ret;
- }
-
+ ret = (void*) babl_space_from_chromaticities (NULL,
+ wX / (wX + wY + wZ),
+ wY / (wX + wY + wZ),
+ red_x, red_y,
+ green_x, green_y,
+ blue_x, blue_y,
+ trc_red, trc_green, trc_blue);
+ ret->space.description = descr;
+ ret->space.copyright = copyright;
+ return ret;
}
}
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index 6593862..ca65279 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -362,4 +362,12 @@ void _babl_space_add_universal_rgb (const Babl *space);
const Babl *
babl_trc_formula_srgb (double gamma, double a, double b, double c, double d);
+
+const Babl *babl_space_match_trc_matrix (const Babl *trc_red,
+ const Babl *trc_green,
+ const Babl *trc_blue,
+ float rx, float ry, float rz,
+ float gx, float gy, float gz,
+ float bx, float by, float bz);
+
#endif
diff --git a/babl/babl-space.c b/babl/babl-space.c
index 8ed8465..20ce40c 100644
--- a/babl/babl-space.c
+++ b/babl/babl-space.c
@@ -772,3 +772,34 @@ void _babl_space_add_universal_rgb (const Babl *space)
babl_space_class_for_each (add_rgb_adapter, (void*)space);
}
+
+const Babl *babl_space_match_trc_matrix (const Babl *trc_red,
+ const Babl *trc_green,
+ const Babl *trc_blue,
+ float rx, float ry, float rz,
+ float gx, float gy, float gz,
+ float bx, float by, float bz)
+{
+ // XXX: extend to iteratre through registered spaces and finding
+ // already registered ones that are close enough duplicates
+ // first registered space (thus also internal babl ones) wins.
+ // this makes using babl to get icc meta data difficult, perhaps
+ // the icc meta data should be passed out-of-band?
+
+ if (trc_red == babl_trc ("sRGB") &&
+ trc_green == babl_trc ("sRGB") &&
+ trc_blue == babl_trc ("sRGB") &&
+ fabs(rx - 0.436042) < 0.001 &&
+ fabs(ry - 0.222492) < 0.001 &&
+ fabs(rz - 0.013916) < 0.001 &&
+ fabs(gx - 0.385122) < 0.001 &&
+ fabs(gy - 0.716915) < 0.001 &&
+ fabs(gz - 0.097063) < 0.001 &&
+ fabs(bx - 0.143053) < 0.001 &&
+ fabs(by - 0.060609) < 0.001 &&
+ fabs(bz - 0.713939) < 0.001)
+ {
+ return babl_space ("sRGB");
+ }
+ return NULL;
+}
diff --git a/babl/babl.h b/babl/babl.h
index 3527a60..01431a0 100644
--- a/babl/babl.h
+++ b/babl/babl.h
@@ -92,12 +92,10 @@ const Babl * babl_trc (const char *name);
* babl_trc_gamma:
*
* Creates a Babl TRC for a specific gamma value, it will be given
- * a name
+ * a name that is a short string representation of the value.
*/
const Babl * babl_trc_gamma (double gamma);
-
-
/**
* babl_space:
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]