ApproximateTransferFunction -> ApproximateCurves
Change-Id: I7afd2bcd58a5ff7a9490c37f3a2e54bbd2cbdbc5
Reviewed-on: https://skia-review.googlesource.com/114300
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/fuzz/fuzz_iccprofile_atf.c b/fuzz/fuzz_iccprofile_atf.c
index 9ec7a42..c06ccb5 100644
--- a/fuzz/fuzz_iccprofile_atf.c
+++ b/fuzz/fuzz_iccprofile_atf.c
@@ -20,7 +20,7 @@
skcms_TransferFunction tf;
float max_error;
- (void)skcms_ApproximateTransferFunction(&p, &tf, &max_error);
+ (void)skcms_ApproximateCurves(p.trc, 3, &tf, &max_error);
(void)max_error;
return 0;
diff --git a/iccdump.c b/iccdump.c
index 57bb0b8..6a1a6d9 100644
--- a/iccdump.c
+++ b/iccdump.c
@@ -268,7 +268,7 @@
svg_curves(fp, 3, profile.trc, kSVG_RGB_Colors);
skcms_TransferFunction approx;
float max_error;
- if (skcms_ApproximateTransferFunction(&profile, &approx, &max_error)) {
+ if (skcms_ApproximateCurves(profile.trc, 3, &approx, &max_error)) {
svg_transfer_function(fp, &approx, "magenta");
}
svg_pop_group(fp);
diff --git a/skcms.h b/skcms.h
index 590b6c8..0212ed3 100644
--- a/skcms.h
+++ b/skcms.h
@@ -124,8 +124,8 @@
// will be used.
bool skcms_Parse(const void*, size_t, skcms_ICCProfile*);
-bool skcms_ApproximateTransferFunction(const skcms_ICCProfile*, skcms_TransferFunction*
- , float* max_error);
+bool skcms_ApproximateCurves(const skcms_Curve* curves, uint32_t num_curves,
+ skcms_TransferFunction* approx, float* max_error);
typedef struct {
uint32_t signature;
diff --git a/src/ICCProfile.c b/src/ICCProfile.c
index 1077690..363f991 100644
--- a/src/ICCProfile.c
+++ b/src/ICCProfile.c
@@ -285,19 +285,21 @@
return false;
}
-bool skcms_ApproximateTransferFunction(const skcms_ICCProfile* profile,
- skcms_TransferFunction* fn,
- float* max_error) {
- if (!profile || !fn) { return false; }
-
- const skcms_Curve* curves = profile->trc;
- if (!curves[0].table_16 || !curves[1].table_16 || !curves[2].table_16) {
+bool skcms_ApproximateCurves(const skcms_Curve* curves, uint32_t num_curves,
+ skcms_TransferFunction* approx, float* max_error) {
+ if (!curves || !approx) {
return false;
}
- uint64_t n = (uint64_t)curves[0].table_entries
- + (uint64_t)curves[1].table_entries
- + (uint64_t)curves[2].table_entries;
+ uint64_t n = 0;
+ for (uint32_t c = 0; c < num_curves; ++c) {
+ // TODO: Support approximating 8 bit curves
+ if (!curves[c].table_entries || !curves[c].table_16) {
+ return false;
+ }
+ n += (uint64_t)curves[c].table_entries;
+ }
+
if (n > INT_MAX) {
return false;
}
@@ -316,7 +318,7 @@
float* t = data + n;
// Merge all channels' tables into a single array.
- for (int c = 0; c < 3; ++c) {
+ for (uint32_t c = 0; c < num_curves; ++c) {
for (uint32_t i = 0; i < curves[c].table_entries; ++i) {
*x++ = i / (curves[c].table_entries - 1.0f);
*t++ = read_big_u16(curves[c].table_16 + 2 * i) * (1 / 65535.0f);
@@ -326,7 +328,7 @@
x = data;
t = data + n;
- bool result = skcms_TransferFunction_approximate(fn, x, t, (int)n, max_error);
+ bool result = skcms_TransferFunction_approximate(approx, x, t, (int)n, max_error);
free(data);
return result;
}
diff --git a/test_only.c b/test_only.c
index 886b9da..e51fc4a 100644
--- a/test_only.c
+++ b/test_only.c
@@ -129,7 +129,7 @@
float max_error;
if (has_single_tf) {
dump_transfer_function(fp, "TRC", &tf);
- } else if (skcms_ApproximateTransferFunction(profile, &tf, &max_error)) {
+ } else if (skcms_ApproximateCurves(profile->trc, 3, &tf, &max_error)) {
if (for_unit_test) {
// The approximated transfer function can vary significantly, due to FMA, etc. In unit
// test mode, we print at reduced precision, and omit 'd' entirely, which can vary in
diff --git a/tests.c b/tests.c
index aada0c7..44e07d8 100644
--- a/tests.c
+++ b/tests.c
@@ -587,7 +587,7 @@
skcms_TransferFunction approx_tf;
float max_error;
- bool approx_tf_result = skcms_ApproximateTransferFunction(&profile, &approx_tf, &max_error);
+ bool approx_tf_result = skcms_ApproximateCurves(profile.trc, 3, &approx_tf, &max_error);
expect(approx_tf_result == !!test->expect_approx_tf);
if (approx_tf_result) {
// For this check, run every byte value through the forward version of one TF, and