summaryrefslogtreecommitdiff
path: root/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c')
-rw-r--r--lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c257
1 files changed, 177 insertions, 80 deletions
diff --git a/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c b/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
index 34bafd78d..adac09a9f 100644
--- a/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
+++ b/lcms2mt/plugins/fast_float/testbed/fast_float_testbed.c
@@ -48,6 +48,18 @@ typedef struct { cmsFloat32Number L, a, b; } Scanline_LabFloat;
// Floating point acuracy for tests
#define EPSILON_FLOAT_TESTS 0.005
+// A flushed printf
+static
+void trace(const char* frm, ...)
+{
+ va_list args;
+
+ va_start(args, frm);
+ vfprintf(stderr, frm, args);
+ fflush(stderr);
+ va_end(args);
+}
+
// The callback function used by cmsSetLogErrorHandler()
static
@@ -56,7 +68,7 @@ void FatalErrorQuit(cmsContext ContextID, cmsUInt32Number ErrorCode, const char
UNUSED_PARAMETER(ContextID);
UNUSED_PARAMETER(ErrorCode);
- printf("** Fatal error: %s\n", Text);
+ trace("** Fatal error: %s\n", Text);
exit(1);
}
@@ -229,7 +241,7 @@ Error:
return rc;
}
-#define CHECK(frm, plane, chans, alpha, ...) if (!checkSingleComputeIncrements(frm, plane, chans, alpha, __VA_ARGS__)) { printf("Format failed!\n"); return 0; }
+#define CHECK(frm, plane, chans, alpha, ...) if (!checkSingleComputeIncrements(frm, plane, chans, alpha, __VA_ARGS__)) { trace("Format failed!\n"); return 0; }
@@ -343,7 +355,7 @@ void Check15bitMacros(void)
{
int i;
- printf("Checking 15 bit <=> 8 bit macros...");
+ trace("Checking 15 bit <=> 8 bit macros...");
for (i = 0; i < 256; i++)
{
@@ -353,7 +365,7 @@ void Check15bitMacros(void)
if (m != i)
Fail("Failed on %d (->%d->%d)", i, n, m);
}
- printf("ok\n");
+ trace("ok\n");
}
// Do an in-depth test by checking all RGB cube of 8 bits, going from profilein to profileout.
@@ -433,19 +445,19 @@ void Check15bitsConversions(cmsContext ContextID)
{
Check15bitMacros();
- printf("Checking accuracy of 15 bits on CLUT...");
+ trace("Checking accuracy of 15 bits on CLUT...");
TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, "test3.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
- printf("Checking accuracy of 15 bits on same profile ...");
+ trace("Checking accuracy of 15 bits on same profile ...");
TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
- printf("Checking accuracy of 15 bits on Matrix...");
+ trace("Checking accuracy of 15 bits on Matrix...");
TryAllValues15(ContextID, cmsOpenProfileFromFile(ContextID, "test5.icc", "r"), cmsOpenProfileFromFile(ContextID, "test0.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
- printf("All 15 bits tests passed OK\n\n");
+ trace("All 15 bits tests passed OK\n\n");
}
// Next test checks results of optimized 16 bits versus raw 16 bits.
@@ -524,11 +536,85 @@ static
void CheckAccuracy16Bits(cmsContext Raw, cmsContext Plugin)
{
// CLUT should be as 16 bits or better
- printf("Checking accuracy of 16 bits CLUT...");
+ trace("Checking accuracy of 16 bits CLUT...");
TryAllValues16bits(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test3.icc", "r"), INTENT_PERCEPTUAL);
- printf("All 16 bits tests passed OK\n\n");
+ trace("All 16 bits tests passed OK\n\n");
+}
+
+
+// Try values that are denormalized, not-a-number and out of range
+static
+void CheckUncommonValues(cmsHPROFILE hlcmsProfileIn, cmsHPROFILE hlcmsProfileOut, cmsInt32Number Intent)
+{
+ union
+ {
+ cmsFloat32Number subnormal;
+ cmsUInt32Number Int;
+
+ } sub_pos, sub_neg;
+
+ Scanline_rgbFloat* bufferIn;
+ Scanline_rgbFloat* bufferPluginOut;
+
+ cmsUInt32Number i, npixels = 100;
+
+ cmsContext Plugin = cmsCreateContext(cmsFastFloatExtensions(), NULL);
+
+ cmsHTRANSFORM xformPlugin = cmsCreateTransformTHR(Plugin, hlcmsProfileIn, TYPE_RGB_FLT, hlcmsProfileOut, TYPE_RGB_FLT, Intent, 0);
+
+
+ sub_pos.Int = 0x00000002;
+ sub_neg.Int = 0x80000002;
+
+ cmsCloseProfile(hlcmsProfileIn);
+ cmsCloseProfile(hlcmsProfileOut);
+
+ if (xformPlugin == NULL) {
+
+ Fail("NULL transform on check uncommon values");
+ }
+
+
+ bufferIn = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+ bufferPluginOut = (Scanline_rgbFloat*)malloc(npixels * sizeof(Scanline_rgbFloat));
+
+ for (i = 0; i < npixels; i++)
+ {
+ bufferIn[i].r = i / 40.0 - 0.5;
+ bufferIn[i].g = i / 20.0 - 0.5;
+ bufferIn[i].b = i / 60.0 - 0.5;
+ }
+
+ cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, npixels);
+
+
+ bufferIn[0].r = NAN;
+ bufferIn[0].g = NAN;
+ bufferIn[0].b = NAN;
+
+ bufferIn[1].r = INFINITY;
+ bufferIn[1].g = INFINITY;
+ bufferIn[1].b = INFINITY;
+
+ bufferIn[2].r = sub_pos.subnormal;
+ bufferIn[2].g = sub_pos.subnormal;
+ bufferIn[2].b = sub_pos.subnormal;
+
+ bufferIn[3].r = sub_neg.subnormal;
+ bufferIn[3].g = sub_neg.subnormal;
+ bufferIn[3].b = sub_neg.subnormal;
+
+ cmsDoTransform(xformPlugin, bufferIn, bufferPluginOut, 4);
+
+ free(bufferIn);
+ free(bufferPluginOut);
+
+ cmsDeleteTransform(xformPlugin);
+
+ cmsDeleteContext(Plugin);
}
+
// --------------------------------------------------------------------------------------------------
// A C C U R A C Y C H E C K S
// --------------------------------------------------------------------------------------------------
@@ -779,7 +865,7 @@ void CheckChangeFormat(cmsContext ContextID)
cmsUInt16Number rgb16[3] = { 10* 257, 120*257, 40*257 };
cmsUInt16Number lab16_1[3], lab16_2[3];
- printf("Checking change format feature...");
+ trace("Checking change format feature...");
hsRGB = cmsCreate_sRGBProfile(ContextID);
hLab = cmsCreateLab4Profile(ContextID, NULL);
@@ -797,7 +883,7 @@ void CheckChangeFormat(cmsContext ContextID)
if (memcmp(lab16_1, lab16_2, sizeof(lab16_1)) != 0)
Fail("Change format failed!");
- printf("Ok\n");
+ trace("Ok\n");
}
@@ -818,7 +904,7 @@ void CheckLab2Roundtrip(cmsContext ContextID)
Scanline_rgb8bits* In;
Scanline_rgb8bits* Out;
- printf("Checking lab2 roundtrip...");
+ trace("Checking lab2 roundtrip...");
hsRGB = cmsCreate_sRGBProfile(ContextID);
hLab = cmsCreateLab2Profile(ContextID, NULL);
@@ -875,7 +961,7 @@ void CheckLab2Roundtrip(cmsContext ContextID)
free(In);
free(Out);
free(lab);
- printf("Ok\n");
+ trace("Ok\n");
}
@@ -883,34 +969,45 @@ void CheckLab2Roundtrip(cmsContext ContextID)
static
void CheckConversionFloat(cmsContext Raw, cmsContext Plugin)
{
- printf("Crash test.");
+ trace("Crash test.");
TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL, FALSE);
- printf("..");
+ trace("..");
TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL, TRUE);
- printf("Ok\n");
+ trace("Ok\n");
- printf("Crash (II) test.");
+ trace("Crash (II) test.");
TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL, FALSE);
- printf("..");
+ trace("..");
TryAllValuesFloatAlpha(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL, TRUE);
- printf("Ok\n");
+ trace("Ok\n");
+
+
+ /*
+ * FIXME!!
+ */
+ trace("Crash (III) test.");
+ CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test3.icc", "r"), INTENT_PERCEPTUAL);
+ trace("..");
+ CheckUncommonValues(cmsOpenProfileFromFile("test5.icc", "r"), cmsOpenProfileFromFile("test0.icc", "r"), INTENT_PERCEPTUAL);
+ trace("Ok\n");
+
// Matrix-shaper should be accurate
- printf("Checking accuracy on Matrix-shaper...");
+ trace("Checking accuracy on Matrix-shaper...");
TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
// CLUT should be as 16 bits or better
- printf("Checking accuracy of CLUT...");
+ trace("Checking accuracy of CLUT...");
TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test5.icc", "r"), cmsOpenProfileFromFile(Raw, "test3.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
// Same profile should give same values (we test both methods)
- printf("Checking accuracy on same profile ...");
+ trace("Checking accuracy on same profile ...");
TryAllValuesFloatVs16(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
TryAllValuesFloat(Raw, Plugin, cmsOpenProfileFromFile(Raw, "test0.icc", "r"), cmsOpenProfileFromFile(Raw, "test0.icc", "r"), INTENT_PERCEPTUAL);
- printf("Ok\n");
+ trace("Ok\n");
}
@@ -945,7 +1042,7 @@ void CheckLab2RGB(cmsContext plugin)
cmsFloat32Number maxInside = 0, maxOutside = 0, L, a, b;
- printf("Checking Lab -> RGB...");
+ trace("Checking Lab -> RGB...");
for (L = 4; L <= 100; L++)
{
for (a = -30; a < +30; a++)
@@ -983,7 +1080,7 @@ void CheckLab2RGB(cmsContext plugin)
}
- printf("Max distance: Inside gamut %f, Outside gamut %f\n", sqrtf(maxInside), sqrtf(maxOutside));
+ trace("Max distance: Inside gamut %f, Outside gamut %f\n", sqrtf(maxInside), sqrtf(maxOutside));
cmsDeleteTransform(hXformNoPlugin);
cmsDeleteTransform(hXformPlugin);
@@ -1012,7 +1109,7 @@ typedef cmsFloat64Number(*perf_fn)(cmsContext ct, cmsHPROFILE hlcmsProfileIn, cm
static
void PerformanceHeader(void)
{
- printf(" MPixel/sec. MByte/sec.\n");
+ trace(" MPixel/sec. MByte/sec.\n");
}
@@ -1052,17 +1149,17 @@ cmsFloat64Number Performance(const char* Title, perf_fn fn, cmsContext ct, const
cmsFloat64Number n = fn(ct, hlcmsProfileIn, hlcmsProfileOut);
- printf("%-30s: ", Title); fflush(stdout);
- printf("%-12.2f %-12.2f", n, n * sz);
+ trace("%-30s: ", Title); fflush(stdout);
+ trace("%-12.2f %-12.2f", n, n * sz);
if (prev > 0.0) {
cmsFloat64Number imp = n / prev;
if (imp > 1)
- printf(" (x %-2.1f)", imp);
+ trace(" (x %-2.1f)", imp);
}
- printf("\n"); fflush(stdout);
+ trace("\n"); fflush(stdout);
return n;
}
@@ -1099,8 +1196,8 @@ void ComparativeCt(cmsContext ct1, cmsContext ct2, const char* Title, perf_fn fn
cmsFloat64Number n2 = fn2(ct2, hlcmsProfileIn, hlcmsProfileOut);
- printf("%-30s: ", Title); fflush(stdout);
- printf("%-12.2f %-12.2f\n", n1, n2);
+ trace("%-30s: ", Title); fflush(stdout);
+ trace("%-12.2f %-12.2f\n", n1, n2);
}
static
@@ -1434,9 +1531,9 @@ void SpeedTest8(void)
cmsFloat64Number t[10];
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S 8 B I T S (D E F A U L T)\n");
- printf("==============================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S 8 B I T S (D E F A U L T)\n");
+ trace("==============================================================\n\n");
fflush(stdout);
PerformanceHeader();
@@ -1447,9 +1544,9 @@ void SpeedTest8(void)
// Note that context 0 has the plug-in installed
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S 8 B I T S (P L U G I N)\n");
- printf("===========================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S 8 B I T S (P L U G I N)\n");
+ trace("===========================================================\n\n");
fflush(stdout);
PerformanceHeader();
@@ -1464,8 +1561,8 @@ void SpeedTest8(void)
static
void SpeedTest15(cmsContext ct)
{
- printf("\n\nP E R F O R M A N C E T E S T S 1 5 B I T S (P L U G I N)\n");
- printf( "===============================================================\n\n");
+ trace("\n\nP E R F O R M A N C E T E S T S 1 5 B I T S (P L U G I N)\n");
+ trace( "===============================================================\n\n");
PerformanceHeader();
Performance("15 bits on CLUT profiles ", SpeedTest15bitsRGB, ct, "test5.icc", "test3.icc", sizeof(Scanline_rgb15bits), 0);
@@ -1481,9 +1578,9 @@ void SpeedTest16(cmsContext ct)
cmsContext noPlugin = cmsCreateContext(0, 0);
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S 1 6 B I T S (D E F A U L T)\n");
- printf("=================================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S 1 6 B I T S (D E F A U L T)\n");
+ trace("=================================================================\n\n");
PerformanceHeader();
Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, noPlugin, "test5.icc", "test3.icc", sizeof(Scanline_rgb16bits), 0);
@@ -1492,9 +1589,9 @@ void SpeedTest16(cmsContext ct)
Performance("16 bits on curves ", SpeedTest16bitsRGB, noPlugin, "*curves", "*curves", sizeof(Scanline_rgb16bits), 0);
Performance("16 bits on CMYK CLUT profiles ", SpeedTest16bitsCMYK, noPlugin, "test1.icc", "test2.icc", sizeof(Scanline_cmyk16bits), 0);
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S 1 6 B I T S (P L U G I N)\n");
- printf("===============================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S 1 6 B I T S (P L U G I N)\n");
+ trace("===============================================================\n\n");
PerformanceHeader();
Performance("16 bits on CLUT profiles ", SpeedTest16bitsRGB, ct, "test5.icc", "test3.icc", sizeof(Scanline_rgb16bits), 0);
@@ -1732,9 +1829,9 @@ void SpeedTestFloat(cmsContext noPlugin, cmsContext plugin)
cmsFloat64Number t[10] = { 0 };
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S F L O A T (D E F A U L T)\n");
- printf("==============================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S F L O A T (D E F A U L T)\n");
+ trace("==============================================================\n\n");
fflush(stdout);
PerformanceHeader();
@@ -1750,9 +1847,9 @@ void SpeedTestFloat(cmsContext noPlugin, cmsContext plugin)
// Note that context 0 has the plug-in installed
- printf("\n\n");
- printf("P E R F O R M A N C E T E S T S F L O A T (P L U G I N)\n");
- printf("===========================================================\n\n");
+ trace("\n\n");
+ trace("P E R F O R M A N C E T E S T S F L O A T (P L U G I N)\n");
+ trace("===========================================================\n\n");
fflush(stdout);
PerformanceHeader();
@@ -1847,11 +1944,11 @@ cmsFloat64Number SpeedTestFloatByUsing16BitsRGB(cmsContext ct, cmsHPROFILE hlcms
static
void ComparativeFloatVs16bits(cmsContext Raw, cmsContext Plugin)
{
- printf("\n\n");
- printf("C O M P A R A T I V E converting to 16 bit vs. using float plug-in.\n");
- printf(" values given in MegaPixels per second.\n");
- printf("====================================================================\n");
- printf(" 16 bits tmp. Float plugin\n");
+ trace("\n\n");
+ trace("C O M P A R A T I V E converting to 16 bit vs. using float plug-in.\n");
+ trace(" values given in MegaPixels per second.\n");
+ trace("====================================================================\n");
+ trace(" 16 bits tmp. Float plugin\n");
fflush(stdout);
Comparative(Raw, Plugin, "Floating point on CLUT profiles ", SpeedTestFloatByUsing16BitsRGB, SpeedTestFloatRGB, "test5.icc", "test3.icc");
@@ -1980,10 +2077,10 @@ cmsFloat64Number SpeedTest8bitLineStride(cmsContext ct, cmsHPROFILE hlcmsProfile
static
void ComparativeLineStride8bits(cmsContext NoPlugin, cmsContext Plugin)
{
- printf("\n\n");
- printf("C O M P A R A T I V E cmsDoTransform() vs. cmsDoTransformLineStride()\n");
- printf(" values given in MegaPixels per second.\n");
- printf("====================================================================\n");
+ trace("\n\n");
+ trace("C O M P A R A T I V E cmsDoTransform() vs. cmsDoTransformLineStride()\n");
+ trace(" values given in MegaPixels per second.\n");
+ trace("====================================================================\n");
fflush(stdout);
@@ -2042,7 +2139,7 @@ void TestGrayTransformPerformance(cmsContext ct)
free(In);
cmsDeleteTransform(ct, hlcmsxform);
- printf("Gray conversion using two gray profiles\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
+ trace("Gray conversion using two gray profiles\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
}
static
@@ -2091,7 +2188,7 @@ void TestGrayTransformPerformance1(cmsContext ct)
free(In);
cmsDeleteTransform(ct, hlcmsxform);
- printf("Gray conversion using two devicelinks\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
+ trace("Gray conversion using two devicelinks\t %-12.2f MPixels/Sec.\n", MPixSec(diff));
}
@@ -2101,17 +2198,17 @@ int main()
cmsContext raw = cmsCreateContext(NULL, NULL);
cmsContext plugin = cmsCreateContext(NULL, NULL);
- printf("FastFloating point extensions testbed - 1.3\n");
- printf("Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved\n");
+ trace("FastFloating point extensions testbed - 1.3\n");
+ trace("Copyright (c) 1998-2020 Marti Maria Saguer, all rights reserved\n");
- printf("\nInstalling error logger ... ");
+ trace("\nInstalling error logger ... ");
cmsSetLogErrorHandler(raw, FatalErrorQuit);
cmsSetLogErrorHandler(plugin, FatalErrorQuit);
- printf("done.\n");
+ trace("done.\n");
- printf("Installing plug-in ... ");
+ trace("Installing plug-in ... ");
cmsPlugin(plugin, cmsFastFloatExtensions());
- printf("done.\n\n");
+ trace("done.\n\n");
CheckComputeIncrements();
@@ -2131,7 +2228,7 @@ int main()
// Floating point functionality
CheckConversionFloat(raw, plugin);
- printf("All floating point tests passed OK\n");
+ trace("All floating point tests passed OK\n");
SpeedTest8(plugin);
SpeedTest16(plugin);
@@ -2143,13 +2240,13 @@ int main()
ComparativeLineStride8bits(raw, plugin);
// Test gray performance
- printf("\n\n");
- printf("F L O A T G R A Y conversions performance.\n");
- printf("====================================================================\n");
+ trace("\n\n");
+ trace("F L O A T G R A Y conversions performance.\n");
+ trace("====================================================================\n");
TestGrayTransformPerformance(plugin);
TestGrayTransformPerformance1(plugin);
- printf("\nAll tests passed OK\n");
+ trace("\nAll tests passed OK\n");
return 0;