centralize internal headers into skcms_internal.h
This is the first of many refactors, roughly:
1) centralize internal headers into skcms_internal.h
2) centralize implementation into skcms.c
3) trim down skcms_internal.h where possible
4) convert skcms.c to skcms.cc
5) update impl of transform to not need Transform_inl.h hack
6) finally start on F16 transforms
In the end we should be left with skcms.h and skcms.cc,
and skcms_internal.h and all our existing test tools.
Change-Id: Ifce1325f0b35e9a7958ee156e3e02e9cdef340e4
Reviewed-on: https://skia-review.googlesource.com/138928
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: Mike Klein <mtklein@chromium.org>
diff --git a/fuzz/fuzz_iccprofile_info.c b/fuzz/fuzz_iccprofile_info.c
index 02c2933..48da5db 100644
--- a/fuzz/fuzz_iccprofile_info.c
+++ b/fuzz/fuzz_iccprofile_info.c
@@ -9,7 +9,6 @@
// of info from it.
#include "../skcms.h"
-#include "../src/Macros.h"
static volatile uint32_t g_FoolTheOptimizer = 0;
@@ -45,7 +44,7 @@
// For TRC tables, test that we can read the first and last entries of each table.
if (p.has_trc) {
- for (int i = 0; i < ARRAY_COUNT(p.trc); ++i) {
+ for (int i = 0; i < 3; ++i) {
g_FoolTheOptimizer += read_table_extents(&p.trc[i]);
}
}
diff --git a/iccdump.c b/iccdump.c
index eb65437..e7368ac 100644
--- a/iccdump.c
+++ b/iccdump.c
@@ -15,11 +15,8 @@
#endif
#include "skcms.h"
+#include "skcms_internal.h"
#include "test_only.h"
-#include "src/ICCProfile.h"
-#include "src/LinearAlgebra.h"
-#include "src/Macros.h"
-#include "src/TransferFunction.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/skcms.gni b/skcms.gni
index f2004ad..fbd816c 100644
--- a/skcms.gni
+++ b/skcms.gni
@@ -4,19 +4,13 @@
# found in the LICENSE file.
skcms_sources = [
+ "skcms.h",
+ "skcms_internal.h",
"src/Curve.c",
- "src/Curve.h",
"src/ICCProfile.c",
- "src/ICCProfile.h",
"src/LinearAlgebra.c",
- "src/LinearAlgebra.h",
- "src/Macros.h",
"src/PortableMath.c",
- "src/PortableMath.h",
- "src/RandomBytes.h",
"src/TransferFunction.c",
- "src/TransferFunction.h",
"src/Transform.c",
- "src/Transform.h",
"src/Transform_inl.h",
]
diff --git a/skcms_internal.h b/skcms_internal.h
new file mode 100644
index 0000000..97fc8de
--- /dev/null
+++ b/skcms_internal.h
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#pragma once
+
+// skcms_internal.h contains APIs shared by skcms' internals and its test tools.
+// Please don't use this header from outside the skcms repo.
+
+#include "skcms.h"
+#include <stdbool.h>
+#include <stdint.h>
+
+#if defined(__cpluscplus)
+extern "C" {
+#endif
+
+// ~~~~ General Helper Macros ~~~~
+
+ // sizeof(x) will return size_t, which is 32-bit on some machines and 64-bit on others.
+ // We have better testing on 64-bit machines, so force 32-bit machines to behave like 64-bit.
+ #define SAFE_SIZEOF(x) ((uint64_t)sizeof(x))
+
+ // Please do not use sizeof() directly, and size_t only when required.
+ // (We have no way of enforcing these requests...)
+
+ #define ARRAY_COUNT(arr) (int)(SAFE_SIZEOF((arr)) / SAFE_SIZEOF(*(arr)))
+
+
+// ~~~~ skcms_Curve ~~~~
+
+ // Evaluate an skcms_Curve at x.
+ float skcms_eval_curve(const skcms_Curve*, float x);
+ float skcms_MaxRoundtripError(const skcms_Curve*, const skcms_TransferFunction*);
+
+
+// ~~~~ skcms_TransferFunction ~~~~
+ bool skcms_TransferFunction_isValid(const skcms_TransferFunction*);
+
+ float skcms_TransferFunction_eval(const skcms_TransferFunction*, float);
+
+ bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*);
+
+ // Fit c,d,f parameters of an skcms_TransferFunction to the first 2 ≤ L ≤ N
+ // evenly-spaced points on an skcms_Curve within a given tolerance, returning L.
+ int skcms_fit_linear(const skcms_Curve*, int N, float tol, float* c, float* d, float* f);
+
+
+// ~~~~ skcms_ICCProfile ~~~~
+
+ bool skcms_GetCHAD(const skcms_ICCProfile* profile, skcms_Matrix3x3* m);
+
+ // 252 of a random shuffle of all possible bytes.
+ // 252 is evenly divisible by 3 and 4. Only 192, 10, 241, and 43 are missing.
+ // Used for ICC profile equivalence testing.
+ extern const uint8_t skcms_252_random_bytes[252];
+
+
+// ~~~~ Linear Algebra ~~~~
+
+ typedef struct { float vals[3]; } skcms_Vector3;
+
+ // It is _not_ safe to alias the pointers to invert in-place.
+ bool skcms_Matrix3x3_invert(const skcms_Matrix3x3*, skcms_Matrix3x3*);
+ skcms_Matrix3x3 skcms_Matrix3x3_concat(const skcms_Matrix3x3* A, const skcms_Matrix3x3* B);
+
+ skcms_Vector3 skcms_MV_mul(const skcms_Matrix3x3*, const skcms_Vector3*);
+
+
+// ~~~~ Portable Math ~~~~
+
+ static const union {
+ uint32_t bits;
+ float f;
+ } inf_ = { 0x7f800000 };
+
+ #define INFINITY_ inf_.f
+
+ static inline float floorf_(float x) {
+ float roundtrip = (float)((int)x);
+ return roundtrip > x ? roundtrip - 1 : roundtrip;
+ }
+
+ static inline float fmaxf_(float x, float y) { return x > y ? x : y; }
+ static inline float fminf_(float x, float y) { return x < y ? x : y; }
+ static inline float fabsf_(float x) { return x < 0 ? -x : x; }
+
+ float log2f_(float);
+ float exp2f_(float);
+ float powf_(float, float);
+
+ static inline bool isfinitef_(float x) { return 0 == x*0; }
+
+
+// ~~~~ Transform ~~~~
+
+ #define FOREACH_Op(M) \
+ M(noop) \
+ M(load_a8) \
+ M(load_g8) \
+ M(load_4444) \
+ M(load_565) \
+ M(load_888) \
+ M(load_8888) \
+ M(load_1010102) \
+ M(load_161616) \
+ M(load_16161616) \
+ M(load_hhh) \
+ M(load_hhhh) \
+ M(load_fff) \
+ M(load_ffff) \
+ M(swap_rb) \
+ M(clamp) \
+ M(invert) \
+ M(force_opaque) \
+ M(premul) \
+ M(unpremul) \
+ M(matrix_3x3) \
+ M(matrix_3x4) \
+ M(lab_to_xyz) \
+ M(tf_r) \
+ M(tf_g) \
+ M(tf_b) \
+ M(tf_a) \
+ M(table_8_r) \
+ M(table_8_g) \
+ M(table_8_b) \
+ M(table_8_a) \
+ M(table_16_r) \
+ M(table_16_g) \
+ M(table_16_b) \
+ M(table_16_a) \
+ M(clut_3D_8) \
+ M(clut_3D_16) \
+ M(clut_4D_8) \
+ M(clut_4D_16) \
+ M(store_a8) \
+ M(store_g8) \
+ M(store_4444) \
+ M(store_565) \
+ M(store_888) \
+ M(store_8888) \
+ M(store_1010102) \
+ M(store_161616) \
+ M(store_16161616) \
+ M(store_hhh) \
+ M(store_hhhh) \
+ M(store_fff) \
+ M(store_ffff)
+
+ typedef enum {
+ #define M(op) Op_##op,
+ FOREACH_Op(M)
+ #undef M
+ } Op;
+
+#if defined(__cpluscplus)
+} // extern "C"
+#endif
diff --git a/src/Curve.c b/src/Curve.c
index a1a3c62..2b99fd7 100644
--- a/src/Curve.c
+++ b/src/Curve.c
@@ -5,9 +5,7 @@
* found in the LICENSE file.
*/
-#include "Curve.h"
-#include "PortableMath.h"
-#include "TransferFunction.h"
+#include "../skcms_internal.h"
#include <assert.h>
static float minus_1_ulp(float x) {
diff --git a/src/Curve.h b/src/Curve.h
deleted file mode 100644
index 1316562..0000000
--- a/src/Curve.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-#include "../skcms.h"
-
-// Evaluate an skcms_Curve at x.
-float skcms_eval_curve(const skcms_Curve*, float x);
-
-float skcms_MaxRoundtripError(const skcms_Curve* curve, const skcms_TransferFunction* inv_tf);
diff --git a/src/ICCProfile.c b/src/ICCProfile.c
index 1f25d16..257e111 100644
--- a/src/ICCProfile.c
+++ b/src/ICCProfile.c
@@ -6,12 +6,7 @@
*/
#include "../skcms.h"
-#include "ICCProfile.h"
-#include "LinearAlgebra.h"
-#include "Macros.h"
-#include "PortableMath.h"
-#include "RandomBytes.h"
-#include "TransferFunction.h"
+#include "../skcms_internal.h"
#include <assert.h>
#include <limits.h>
#include <stdlib.h>
diff --git a/src/ICCProfile.h b/src/ICCProfile.h
deleted file mode 100644
index 39967a1..0000000
--- a/src/ICCProfile.h
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-#include <stdbool.h>
-
-bool skcms_GetCHAD(const skcms_ICCProfile* profile, skcms_Matrix3x3* m);
diff --git a/src/LinearAlgebra.c b/src/LinearAlgebra.c
index fb35e5c..1cd8b3c 100644
--- a/src/LinearAlgebra.c
+++ b/src/LinearAlgebra.c
@@ -6,8 +6,7 @@
*/
#include "../skcms.h"
-#include "LinearAlgebra.h"
-#include "PortableMath.h"
+#include "../skcms_internal.h"
#include <float.h>
bool skcms_Matrix3x3_invert(const skcms_Matrix3x3* src, skcms_Matrix3x3* dst) {
diff --git a/src/LinearAlgebra.h b/src/LinearAlgebra.h
deleted file mode 100644
index 10b1226..0000000
--- a/src/LinearAlgebra.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-#include <stdbool.h>
-
-typedef struct { float vals[3]; } skcms_Vector3;
-
-// It is _not_ safe to alias the pointers to invert in-place.
-bool skcms_Matrix3x3_invert(const skcms_Matrix3x3*, skcms_Matrix3x3*);
-skcms_Matrix3x3 skcms_Matrix3x3_concat(const skcms_Matrix3x3* A, const skcms_Matrix3x3* B);
-
-skcms_Vector3 skcms_MV_mul(const skcms_Matrix3x3*, const skcms_Vector3*);
diff --git a/src/Macros.h b/src/Macros.h
deleted file mode 100644
index 6bf9c5e..0000000
--- a/src/Macros.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-// sizeof(x) will return size_t, which is 32-bit on some machines and 64-bit on others.
-// We have better testing on 64-bit machines, so force 32-bit machines to behave like 64-bit.
-#define SAFE_SIZEOF(x) ((uint64_t)sizeof(x))
-
-// Please do not use sizeof() directly, and size_t only when required.
-// (We have no way of enforcing these requests...)
-
-#define ARRAY_COUNT(arr) (int)(SAFE_SIZEOF((arr)) / SAFE_SIZEOF(*(arr)))
diff --git a/src/PortableMath.c b/src/PortableMath.c
index b50cb0f..52e8b7d 100644
--- a/src/PortableMath.c
+++ b/src/PortableMath.c
@@ -6,7 +6,7 @@
*/
#include "../skcms.h"
-#include "PortableMath.h"
+#include "../skcms_internal.h"
#include <limits.h>
#include <string.h>
diff --git a/src/PortableMath.h b/src/PortableMath.h
deleted file mode 100644
index 58a2fa8..0000000
--- a/src/PortableMath.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-static const union {
- uint32_t bits;
- float f;
-} inf_ = { 0x7f800000 };
-
-#define INFINITY_ inf_.f
-
-static inline float floorf_(float x) {
- float roundtrip = (float)((int)x);
- return roundtrip > x ? roundtrip - 1 : roundtrip;
-}
-
-static inline float fmaxf_(float x, float y) { return x > y ? x : y; }
-static inline float fminf_(float x, float y) { return x < y ? x : y; }
-static inline float fabsf_(float x) { return x < 0 ? -x : x; }
-
-float log2f_(float);
-float exp2f_(float);
-float powf_(float, float);
-
-static inline bool isfinitef_(float x) { return 0 == x*0; }
diff --git a/src/RandomBytes.h b/src/RandomBytes.h
deleted file mode 100644
index a6191a5..0000000
--- a/src/RandomBytes.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-#include <stdint.h>
-
-// 252 of a random shuffle of all possible bytes.
-// 252 is evenly divisible by 3 and 4. Only 192, 10, 241, and 43 are missing.
-extern const uint8_t skcms_252_random_bytes[252];
diff --git a/src/TransferFunction.c b/src/TransferFunction.c
index 0e3467c..7bab9d9 100644
--- a/src/TransferFunction.c
+++ b/src/TransferFunction.c
@@ -6,11 +6,7 @@
*/
#include "../skcms.h"
-#include "Curve.h"
-#include "LinearAlgebra.h"
-#include "Macros.h"
-#include "PortableMath.h"
-#include "TransferFunction.h"
+#include "../skcms_internal.h"
#include <assert.h>
#include <limits.h>
#include <string.h>
diff --git a/src/TransferFunction.h b/src/TransferFunction.h
deleted file mode 100644
index 1f32831..0000000
--- a/src/TransferFunction.h
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#pragma once
-
-// TransferFunction.h contains skcms-private APIs for working with skcms_TransferFunction.
-
-#include <stdbool.h>
-
-bool skcms_TransferFunction_isValid(const skcms_TransferFunction*);
-
-float skcms_TransferFunction_eval(const skcms_TransferFunction*, float);
-
-bool skcms_TransferFunction_invert(const skcms_TransferFunction*, skcms_TransferFunction*);
-
-// Fit c,d,f parameters of an skcms_TransferFunction to the first 2 < L ≤ N
-// evenly-spaced points on an skcms_Curve within a given tolerance, returning L.
-int skcms_fit_linear(const skcms_Curve*, int N, float tol, float* c, float* d, float* f);
diff --git a/src/Transform.c b/src/Transform.c
index ebfd0ce..2f4216b 100644
--- a/src/Transform.c
+++ b/src/Transform.c
@@ -6,12 +6,7 @@
*/
#include "../skcms.h"
-#include "Curve.h"
-#include "LinearAlgebra.h"
-#include "Macros.h"
-#include "PortableMath.h"
-#include "TransferFunction.h"
-#include "Transform.h"
+#include "../skcms_internal.h"
#include <assert.h>
#include <limits.h>
#include <stdint.h>
diff --git a/src/Transform.h b/src/Transform.h
deleted file mode 100644
index 6eda899..0000000
--- a/src/Transform.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-// Op is a type used by both Transform.c and Transform_inl.h.
-
-#pragma once
-
-#define FOREACH_Op(M) \
- M(noop) \
- M(load_a8) \
- M(load_g8) \
- M(load_4444) \
- M(load_565) \
- M(load_888) \
- M(load_8888) \
- M(load_1010102) \
- M(load_161616) \
- M(load_16161616) \
- M(load_hhh) \
- M(load_hhhh) \
- M(load_fff) \
- M(load_ffff) \
- M(swap_rb) \
- M(clamp) \
- M(invert) \
- M(force_opaque) \
- M(premul) \
- M(unpremul) \
- M(matrix_3x3) \
- M(matrix_3x4) \
- M(lab_to_xyz) \
- M(tf_r) \
- M(tf_g) \
- M(tf_b) \
- M(tf_a) \
- M(table_8_r) \
- M(table_8_g) \
- M(table_8_b) \
- M(table_8_a) \
- M(table_16_r) \
- M(table_16_g) \
- M(table_16_b) \
- M(table_16_a) \
- M(clut_3D_8) \
- M(clut_3D_16) \
- M(clut_4D_8) \
- M(clut_4D_16) \
- M(store_a8) \
- M(store_g8) \
- M(store_4444) \
- M(store_565) \
- M(store_888) \
- M(store_8888) \
- M(store_1010102) \
- M(store_161616) \
- M(store_16161616) \
- M(store_hhh) \
- M(store_hhhh) \
- M(store_fff) \
- M(store_ffff)
-
-typedef enum {
- #define M(op) Op_##op,
- FOREACH_Op(M)
- #undef M
-} Op;
diff --git a/src/Transform_inl.h b/src/Transform_inl.h
index fd3100a..34dcbbf 100644
--- a/src/Transform_inl.h
+++ b/src/Transform_inl.h
@@ -7,7 +7,7 @@
// Intentionally NO #pragma once
-#include "Transform.h"
+#include "../skcms_internal.h"
// This file is included from src/Transform.c, with some values and types pre-defined:
// N: depth of all vectors, 1,4,8, or 16
diff --git a/test_only.c b/test_only.c
index 03c9718..fea2b87 100644
--- a/test_only.c
+++ b/test_only.c
@@ -10,9 +10,7 @@
#endif
#include "skcms.h"
-#include "src/PortableMath.h"
-#include "src/RandomBytes.h"
-#include "src/TransferFunction.h"
+#include "skcms_internal.h"
#include "test_only.h"
#include <stdlib.h>
#include <string.h>
diff --git a/tests.c b/tests.c
index 8116b89..28f7802 100644
--- a/tests.c
+++ b/tests.c
@@ -11,11 +11,8 @@
#endif
#include "skcms.h"
-#include "src/LinearAlgebra.h"
-#include "src/Macros.h"
-#include "src/PortableMath.h"
+#include "skcms_internal.h"
#include "test_only.h"
-#include "src/TransferFunction.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>