[babl] babl: handle 7 parameter ICC v4 TRCs
- From: Øyvind "pippin" Kolås <ok src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [babl] babl: handle 7 parameter ICC v4 TRCs
- Date: Fri, 7 Aug 2020 20:00:55 +0000 (UTC)
commit b61af1caa1b7f0282ade13493e6a517c112934ec
Author: Øyvind Kolås <pippin gimp org>
Date: Fri Aug 7 21:59:36 2020 +0200
babl: handle 7 parameter ICC v4 TRCs
babl/babl-icc.c | 21 ++++++++-------------
babl/babl-internal.h | 2 +-
babl/babl-trc.c | 28 +++++++++++++++++++---------
3 files changed, 28 insertions(+), 23 deletions(-)
---
diff --git a/babl/babl-icc.c b/babl/babl-icc.c
index a21888f70..aa5a3862d 100644
--- a/babl/babl-icc.c
+++ b/babl/babl-icc.c
@@ -386,16 +386,16 @@ babl_trc_from_icc (ICC *state,
break;
case 3:
{
- float a,b,c,d;
+ float a,b,c,d, e, f;
g = icc_read (s15f16, offset + 12 + 4 * 0);
a = icc_read (s15f16, offset + 12 + 4 * 1);
b = icc_read (s15f16, offset + 12 + 4 * 2);
c = icc_read (s15f16, offset + 12 + 4 * 3);
d = icc_read (s15f16, offset + 12 + 4 * 4);
- //fprintf (stderr, "%f %f %f %f %f\n", g, a, b, c, d);
- return babl_trc_formula_srgb (g, a, b, c, d);
+ e = 0.0f;
+ f = 0.0f;
+ return babl_trc_formula_srgb (g, a, b, c, d, e, f);
}
- break;
case 4:
{
float a,b,c,d,e,f;
@@ -406,15 +406,10 @@ babl_trc_from_icc (ICC *state,
d = icc_read (s15f16, offset + 12 + 4 * 4);
e = icc_read (s15f16, offset + 12 + 4 * 5);
f = icc_read (s15f16, offset + 12 + 4 * 6);
- fprintf (stderr, "%f %f %f %f %f %f %f\n",
- g, a, b, c, d, e, f);
- {
- fprintf (stderr, "unhandled parametric sRGB formula TRC type %i\n", function_type);
- *error = "unhandled sRGB formula like TRC";
- return babl_trc_gamma (2.2);
- }
- }
- break;
+ return babl_trc_formula_srgb (g, a, b, c, d, e, f);
+ }
+ case 1: // NYI
+ case 2: // NYI - can share code, like srgb formulas
default:
*error = "unhandled parametric TRC";
fprintf (stderr, "unhandled parametric TRC type %i\n", function_type);
diff --git a/babl/babl-internal.h b/babl/babl-internal.h
index b3c97854f..1efdb0f2f 100644
--- a/babl/babl-internal.h
+++ b/babl/babl-internal.h
@@ -385,7 +385,7 @@ babl_conversion_create_name (Babl *source, Babl *destination, int type,
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);
+babl_trc_formula_srgb (double gamma, double a, double b, double c, double d, double e, double f);
const Babl *babl_space_match_trc_matrix (const Babl *trc_red,
diff --git a/babl/babl-trc.c b/babl/babl-trc.c
index e76bb9201..cfb31b1c3 100644
--- a/babl/babl-trc.c
+++ b/babl/babl-trc.c
@@ -165,16 +165,19 @@ _babl_trc_formula_srgb_from_linear (const Babl *trc_,
float b = trc->lut[2];
float c = trc->lut[3];
float d = trc->lut[4];
- if (x > c * d) // XXX: verify that this math is the correct inverse
+ float e = trc->lut[5];
+ float f = trc->lut[6];
+
+ if (x - f > c * d) // XXX: verify that this math is the correct inverse
{
- float v = _babl_trc_gamma_from_linear ((Babl *) trc, x);
+ float v = _babl_trc_gamma_from_linear ((Babl *) trc, x - f);
v = (v-b)/a;
if (v < 0.0 || v >= 0.0)
return v;
return 0.0;
}
if (c > 0.0)
- return x / c;
+ return (x - e) / c;
return 0.0;
}
@@ -188,12 +191,14 @@ _babl_trc_formula_srgb_to_linear (const Babl *trc_,
float b = trc->lut[2];
float c = trc->lut[3];
float d = trc->lut[4];
+ float e = trc->lut[5];
+ float f = trc->lut[6];
if (x >= d)
{
- return _babl_trc_gamma_to_linear ((Babl *) trc, a * x + b);
+ return _babl_trc_gamma_to_linear ((Babl *) trc, a * x + b) + e;
}
- return c * x;
+ return c * x + f;
}
static inline float
@@ -479,20 +484,25 @@ babl_trc_formula_srgb (double g,
double a,
double b,
double c,
- double d)
+ double d,
+ double e,
+ double f)
{
char name[128];
int i;
- float params[5]={g, a, b, c, d};
+ float params[7]={g, a, b, c, d, e, f};
if (fabs (g - 2.400) < 0.01 &&
fabs (a - 0.947) < 0.01 &&
fabs (b - 0.052) < 0.01 &&
fabs (c - 0.077) < 0.01 &&
- fabs (d - 0.040) < 0.01)
+ fabs (d - 0.040) < 0.01 &&
+ fabs (e - 0.000) < 0.01 &&
+ fabs (f - 0.000) < 0.01
+ )
return babl_trc ("sRGB");
- snprintf (name, sizeof (name), "%.6f %.6f %.4f %.4f %.4f", g, a, b, c, d);
+ snprintf (name, sizeof (name), "%.6f %.6f %.4f %.4f %.4f %.4f %.4f", g, a, b, c, d, e, f);
for (i = 0; name[i]; i++)
if (name[i] == ',') name[i] = '.';
while (name[strlen(name)-1]=='0')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]